Using the has() method a Laravel BelongsTo relation -


i have activity model , level model. each activity has 1 level, have following on activity:

function level() {    return $this->belongsto('level'); } 

and on level:

function activities() {    return $this->hasmany('activity'); } 

i need search activities have particular level, doing this:

$searchdata = 'beginner';  $query = $query->has(array('level' => function($query) use ($searchdata) {     $query->where('name', 'like', '%' . $searchdata . '%'); })); 

using throws logicexception:

has method invalid on "belongsto" relations. 

so i've either got relationship wrong or need build query in different way.

any suggestions?

just close one, off answered in comments @torkiljohnsen.

i'd taken code part of application has many many relationship , pivot table. looking @ again beginning, activity model has level_id can this:

$query->wherelevel_id(x) 

just out of interest though, if didn't have id , instead had string of entry in level table, there way in way trying? presumably sort of closure looks level name , returns id?


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -