我正试图在laravel雄辩的关系中访问公司变量,但我得到错误未定义的变量。
控制器
$assignedCases = AddressCaseAssign::with(['addresses' => function ($query) {
$query->where('company_id', '=',$request->company);
}])->where('user_id',$request->executive)
->get();
模型
public function addresses(){
return $this->belongsTo(Address::class,'address_id');
}
答案 0 :(得分:0)
您需要使用$request
关键字
use
$assignedCases = AddressCaseAssign::with(['addresses' => function ($query) use ($request) {
$query->where('company_id', '=',$request->company);
}])->where('user_id',$request->executive)
->get();