laravel - One To Many, Many To Many -


$trell = trell::find($trell_id);  $builder = $trell->builders();  $codes = $builder->codes(); //undefined method codes... 

so undefined method on codes, relationships following: why doesn't work?

trell has 1 defined in model:

public function builders() {     return $this->hasone('appsales\\models\\builders'); } 

builder has codes defined:

public function codes() {     return $this->hasmany('appsales\\models\\codes'); } 

codes has:

public function builders() {     return $this->belongsto('appsales\\models\\builders'); }  $trell->with('builders.codes')->get()->toarray(); works, want "one codes" filtering (where in sql) is. 

it doesn't work because call relationship-function doesn't return model relationship.

<?php  $trell = trell::find($trell_id);  $builder = $trell->builders(); /**  * $builder of type \illuminate\database\eloquent\relations\hasone  * not have method codes()  * don't want relationship, want property model.  * call property , not function  */  $buildermodel = $trell->builders;  $codes = $buildermodel->codes;  /**  * $codes contains codes collection of models. if want  * filter them, relationship / query object , use   * regular query builder functions:  */  $codes = $buildermodels->codes()->where('key', $value)->get(); 

you can load trell model:

$trells = trell::with([     'builders.codes' => function($query) {          $query->where('key1', $value1);     },  ])->get(); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -