Support the ongoing development of Laravel.io →
Database Eloquent Packages
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

altercode altercode Joined 8 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.