Answer the question
In order to leave comments, you need to log in
How to correctly display a child category by alias from the URL?
Dear Khabrovites, please tell me how to correctly display the contents of a child category by alias from the URL?
I have two tables categories and subcategories which have "id" columns, the subcategories table also has a category_id foreign key associated with the id in the categories table.
There are also two models:
class Category extends Model
{
public function subcategory()
{
return $this->hasMany('App\Subcategory');
}
}
class Subcategory extends Model
{
public function category()
{
return $this->belongsTo('App\Category')->category_id;
}
}
class SubcategoryController extends Controller
{
public function show(Subcategory $subcategory)
{
$subcategory = Subcategory::find($subcategory);
return view('dashboard.subcategories.show', compact('subcategory'));
}
}
Answer the question
In order to leave comments, you need to log in
Lost a little, it was necessary to leave it like this:
class SubcategoryController extends Controller
{
public function show(Subcategory $subcategory)
{
return view('dashboard.subcategories.show', compact('subcategory'));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question