Answer the question
In order to leave comments, you need to log in
How to apply global stubs to lazy loading?
Hello, tell me how to apply the global preparation to lazy loading?
We have a model
Region::with('city')->get();
или
Region::all();
public function city()
{
return $this->belongsToMany('App\City','region_city','region_id','city_id');
}
class AccountScopes implements Scope
{
public function apply(Builder $builder, Model $model)
{
$builder->where('account_id', '=', 1);
}
}
select * from `regions` where `account_id` = 1
select `citys`.*, `regions`.`region_id` as `pivot_region_id`, `region_city`.`city_id` as `pivot_gorodid` from `city` inner join `region_city` on `city`.`id` = `region_city`.`city_id` where `region_city`.`region_id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question