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);
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community