how to make filtering concat in subqueries in laravel 5.
Here is my controller code :
$loan_number = $request->loan_number;
$borrower = $request->borrower;
$investors = $request->investors;
$Query = DB::table('loan')->select([ 'loan.loan_number',
DB::raw("(SELECT concat(users.firstname,' ',users.lastname) FROM users where borrower.user_id = users.id ) as borrower,loan.amount,loan.created_at as loan_date, (select offer.created_at from offer where offer.investor_id = investor.id order by offer.created_at ASC LIMIT 1) as join_date,
(select users.id from users where investor.user_id = users.id) as investor_id, (select concat(users.firstname,' ',users.lastname) from users where investor.user_id = users.id) AS investor, offer.offer_number,offer.amount,
(SELECT DISTINCT application.status from application where application.stat_id = loan.status) as loan_status ") ])
->leftJoin('offer', function($join) {
$join->on('loan.id', '=', 'offer.loan_id');
})
->join('borrower', function($join) {
$join->on('borrower.id', '=', 'loan.borrower_id');
})
->join('investor', function($join) {
$join->on('investor.id', '=', 'offer.investor_id');
});
if (!empty($loan_number)){
$Query = $Query->where('loan.loan_number', 'like', '%'.$loan_number.'%');
}
if (!empty($borrower)){
$Query = $Query->where(I DONT KNOW WHAT SHOULD I DO HERE, HELP PLEASE );
}
if (!empty($investors)){
$Query = $Query->where(I DONT KNOW WHAT SHOULD I DO HERE, HELP PLEASE );
}
$result = $Query->where('loan.status','<>',999)->orderBy('loan.loan_number', 'desc')->paginate($this->paginate)
->appends('loan_number',$loan_number)->appends('borrower',$borrower)->appends('investors',$investors);
return view('oblagio.investors-investment.index',[
'result' => $result,
'loan_number' => $loan_number,
'borrower' => $borrower,
'investors' => $investors,
]);
to filter $loan_number worked well, but I dont know how to filtering/add "where clause" to filter $borrower & $investors, because they're concat. I've tried to add this code to the code above like this:
....DB::raw("(SELECT concat(users.firstname,' ',users.lastname) FROM users where borrower.user_id = users.id and concat(users.firstname,' ',users.lastname) like '%cyber%') as borrower,..........etc.
But the result is : The screenshot also display data that doesn't have value. I just want to display data that only has value. I hope anyone help me here, Thanks in advance.
via arbong