I build a search form which will select markers from database where date is inserted in datapicker. That works fine but , when I add time I get error .
I rebuilded a query to something like that :
$datefrom = $request->input('datefrom');
$dateto = $request->input('dateto');
$timefrom = $request->input('timefrom');
$timfrom = $timefrom.':00';
$timeto = $request -> input('timeto');
$timto = $timeto.':00';
$type = $request->input('type');
$maps = Map::select('lat','lng',$type,'temp','humidity','date','time')
->where(function($query){
$query->whereBetween('date',array($datefrom,$dateto))
->whereBetween('time',array($timfrom,$timto));
})
->get();
When I enter check on search form I get error :
Undefined variable : $datefrom etc.
Any help ?
You've to pass it to the function using use
like :
->where(function($query) use ($datefrom){
$query->whereBetween('date',array($datefrom,$dateto))
->whereBetween('time',array($timfrom,$timto));
})
If you've more than one you could pass them like :
->where(function($query) use ($datefrom,$dateto,$timfrom,$timto){
$query->whereBetween('date',array($datefrom,$dateto))
->whereBetween('time',array($timfrom,$timto));
})
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With