How would you handle a url like {category}/{subject}/{page title}. Would it be compared with three seperate tables or one table or would the parameters be compared in the controller or model with the relationships? How do people handle SEO friendly url's in Laravel?
Framework has really nothing to say here. This works everywhere the same way. At first, all your models need to have slugs that will be used inside URLs - there is an awesome package that provides this outside the box - https://github.com/spatie/laravel-sluggable. Secondly, you need to create URLs that take all these slugs as parameters.
Thank you for your response, but I
have slug columns and pass them through as parameters, but how would you then compare these separate tables so the The chain is validated so you would come to the right page at the end of the url?
//Controller
public function show($categorySlug,$subjectSlug,$pageSlug)
{
$page = Page::whereSlug($pageSlug)
->whereHas('category', function ($query) use ($categorySlug) {
$query->whereSlug($categorySlug);
})
->whereHas('category.subject', function ($query) use ($subjectSlug) {
$query->whereSlug($subjectSlug);
})->first()
return view('pages.show',compact('page'));
}
//Models
class Page extends Model {
public function category()
{
return $this->belongsTo('App\Category');
}
}
class Category extends Model {
public function subject()
{
return $this->belongsTo('App\Subject');
}