well the schema that you have is correct, with that schema you could define the model like this:
public function category(){
return $this->belongsTo("Category", "parent");
}
now for the routing thing it sound to me that you need to traverse the category tree backwards. And I wouldn't have that kind of routing
domain.com/parent_category/child_1/child_2/child_3/child_N/item_id
having to many '/' is bad practice for SEO. Instead I would provide a breadcrumbs navigation for each item, and the routing would be
domain.com/itemType/item
easier for the bots to read.
To generate the breadcrumb type just go backwards on that category
//return a collection of categories
public function traverse_backwards(){
$collection = array();
$i = $this;
while($i != NULL)
//add category to collection
$collection[] = $i;
//go back one level
$i = $i->Category::find($i->parent);
}
return $collection;
}
This code has not been tested, is just for showing the logic behind the solution.
please check my question out. http://laravel.io/forum/08-18-2014-should-i-rely-on-an-abstract-structure-when-doing-a-php-application
Thank you so much for your response! That's good insight into what the bots will read. I could keep the url's shorter. I will probably just use a pattern closer to what you suggest.
Thank you!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community