Do you mean eager loading CategoryLangs with their Category? Look at eager loading here:
http://laravel.com/docs/eloquent#eager-loading
toHierarchy only orders/nests a collection that you have retrieved.
Eager loading:
$tree = Category::with('CategoryLang')->all()->toHierarchy();
Are you trying to load categories that have a CategoryLang with language_id = 1? If so, look at the section on Eager Load Constraints. You'd do it like this:
/* substitute category_langs with whatever method you're using for your relationship */
$users = Category::with(array('category_langs' => function($query)
{
$query->where('language_id', 1);
}))->get();
Just curious -- what is a CategoryLang? If you're trying to offer a translation of a category or something, there is a whole localization interface available for you to do that. http://laravel.com/docs/localization
Thanks this works perfect!
I'm trying to make a multilanguages category tree. In CategoryLang model I have fields like name etc. that can be edited from admin panel in all available languages.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community