Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

please read this http://laravel.com/docs/5.1/collections and take a look at sort() or sortBy()

0

my codes .

 public function categories()
    {
        return $this->hasOne('App\Models\Categories','id');
    }

    public function products()
    {
        return $this->hasMany('App\Models\Products','cat_id');
    }

  public function children()
    {
        return $this->hasMany('App\Models\Categories', 'parent_id', 'id')->with('products')->select(array('id', 'name','slug','parent_id'));
    }




$lastID = explode('-',$id);
        $find = Categories::find(last($lastID));
        if($find['parent_id'] == 0){
            $show = $find->children->toArray();
        }else{
            $products = $find->products->toArray();
            $show     = $find;
        }
        var_dump($show);

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

zelter26 zelter26 Joined 9 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.