Reputation: 6007
I need to run a select on multiple database tables using Laravel 5.6
and I get parameters from the post $request
. Now I need get back the records only if the give values are equvalent the record's values.
I want to do something like this, but this get back every client and section data, no matter what's happening in loan's query part:
Casefile::with([
'client',
'loan' => function($query) use($request) {
$query->where('bank_name','REGEXP',$request->bank_name)
},
'section'
])->where($find)->get();
I want get back the entire record only if the bank_name
is match with the $request->bank_name
.
How can I do this?
Upvotes: 1
Views: 887
Reputation: 25906
Try this:
Casefile::with([
'client',
'section'
])->whereHas('loan', function($query) use($request) {
$query->where('bank_name','REGEXP', $request->bank_name)
})->where($find)->get();
Upvotes: 2