laravel - Select item by specific property -
I am working in Laravel 4, I can simplify my model:
Maximizes the class function of the public function chod ()} (return $ this-> STTO ('chode', 'chod_id');}} class tad spreads \ supernatural {public function food ( ) {Return $ this-> affiliation mail ('food');}} class food spreads \ supernatural {public event meal projects (return) {return $ this-> hamine ('food professional');} } category Expanded \ Eloquent {public function propertyType () {return $ this-> affiliation ('property type', 'property_type_id');}} and I property_type_id < / Em> I want to select MealProperty . I was doing it like this: $ prop = $ dayVariant-> chod- & gt; Food- & Gt; first () -> foodfood () -> where ('property_type_id', '=', $ Foo) - & gt; first (); It is necessary that for every meal, get 5 of the same food properties . It works well, but I do not know how to load the eager load to reduce the queries to reduce the database. ('BreakfastChod.meals.mealProperties') with the & quot; dayVariant = DayVariant :: & gt; (); I can do it this way and then iterate over all food manager , but I'm looking for better way. Probably with odds, I can only get meals , which will be needed and it will be repeated on them. What is the better way to get specific properties? If not, how can I use the barriers with my model? I tried to do it, but it fails. $ dayVariant = DayVariant :: whereHas ('breakfastChod.meals.mealProperties', function ($ query) {$ query-> where ('property_type_id', '=', $ constant ['Nutr_ids'] ['kcal']);}) - & gt; first (); Thanks for every reply!
You can do this in terms of property or try dayVariant like you:
// $ properties = MealProperty :: whereIn ('property_type_id', $ foo) - & gt; ('Meal.chods .dayVariants') - & gt; Find (); // $ dayVariant = DayVariant :: From (['chod.meals.mealProperties' => Use function ($ q) ($ foo) {$ q-> where ('property_type_id', $ foo );}]) - & gt; first ();
Comments
Post a Comment