In my case, I have to filter records by using from-date and to-date ,
I have tired with where between But it works only if I enter both from-date and to-date
public function searchCustomers(Request $request, CustomerProfile $user)
{
$fromDate = $request->get('from_date');
$toDate = $request->get('to_date');
$user = $user->newQuery();
if ($request->has('city')) {
$user->where('city', $request->input('city'));
}
if ($request->has('from_date') && $request->has('to_date')) {
$user->whereBetween('date_of_visit', [$fromDate, $toDate]);
}
$results = $user->get();
return response()->json($results);
}
But sometimes I just want to search with only from-date, and sometimes I want to search with only to-date, and sometimes I want to search with both from date and to-date,
How can I get above output??
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2vEdshD
via IFTTT
Aucun commentaire:
Enregistrer un commentaire