1

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?

netdjw
  • 5,419
  • 21
  • 88
  • 162

1 Answers1

2

Try this:

Casefile::with([
    'client',
    'section'
])->whereHas('loan', function($query) use($request) {
     $query->where('bank_name','REGEXP', $request->bank_name)
})->where($find)->get();
Jonas Staudenmeir
  • 24,815
  • 6
  • 63
  • 109