dane5890's avatar

Still Unable To Get The Parent Category Slug For Sub Categories

I'm back Laravel community. I previously posted on how to automatically get the parent category slug for the sub categories, sub sub categories and the sub sub sub categories pages. Independently, I can get the slugs for the sub categories and so on automatically, no problem. But when I try to incorporate the parent category slug, I continue to get errors. Trying to post

{category}

Doesn't have any effect. I'm sure I put together the appropriate model relationships. I can call the parent category slug with this relationship

  public function catsubliner() {

  return $this->belongsTo(HairBlogCategory::class,'category_id','id');

}

But I continue to get a 404 error. I'm trying to use the URL::to method like this

{{ URL::to('/natural-hair-blogs/s').'/'.$subcategory->catsubliner->slug.'/'.$subcategory->slug }}

Any help is appreciated.

0 likes
2 replies
Sinnbeck's avatar

Show the route as well. How does that url look when rendered?

dane5890's avatar

@Sinnbeck here's the route

Route::get('/natural-hair-blogs/s/{id}'

The route should look something like this

localhost:8000/natural-hair-blogs/s/health-blogs/healthy-eating-blogs-w-healthy-food-blogs

I'm trying to replicate the same thing for the sub sub categories and the sub sub sub categories, and eventually the same thing for the blog url.

Please or to participate in this conversation.