Aug 11, 2018
0
Level 2
Related models in query filter
Hello, Laracasts! I try to make search by my related models, parameters to query filter I pass from search form inputs. Models are:
class Card extends Model
{
public function Doer()
{
return $this->hasMany('App\Doer,'card_id');
}
}
class Doer extends Model
{
public function Card()
{
return $this->belongsTo('App\Card');
}
public function City()
{
return $this->belongsTo('App\City','city_id');
}
}
and
class City extends Model
{
public function Doer()
{
return $this->hasMany('App\Doer','city_id');
}
}
I want to select only Cards which number == $request->input('number') and doer only from city where city == $request->input('city').
I can get Cards with Doers:
$x=Card::with([ 'Doer'=>function($query)
{
//some conditions ???
}
])->get( );
But how to select only doer which id = City.id and City.description ==$request->input('city')?
Please or to participate in this conversation.