Level 75
Use conditional clauses instead of multiple if.
$data = DB::table('Client_Inbound_Transactions as t')
->leftJoin('Client_Accounts as c','c.ClientID', 't.ClientID')
->select('c.ClientID as ClientID', 't.load_type AS LoadType')
->whereIn('c.Client_Type', ['Inbound', 'Outbound'])
->when($loadType, function ($query, $loadType) {
return $query->where('load_type', $loadtType);
})->when($start_date, function ($query, $start_date) {
return $query->whereDate('t.Timestamp', '>=', $start_date);
})->when($end_date, function ($query, $end_date) {
return $query->whereDate('t.Timestamp', '<=', $end_date);
})->get();
https://laravel.com/docs/8.x/queries#conditional-clauses
And that error you have an extra parenthesis there.
It has to be like this
->whereIn('c.Client_Type', ['Inbound', 'Outbound']);
And not this one
->whereIn('c.Client_Type', ['Inbound', 'Outbound']));
^ - here is the problem
1 like