I am trying to filter my results. For this i have following query:
$destinations = $request['destinations'];
if($request->has('destinations'))
{
$trips = Trip::where('status','=',1)->whereHas('destinations', function($q) {
$q->where('destinationsid', '=', $destinations);
})->get();
}else{
echo "No destination provided";
}
But I'm getting undefined variable $destinations. If i replace $destinations with any id (6) it shows results. I have also tried to echo $destinations outside the query, it is returning array. What is wrong here? Can anyone help me?
Try to add the use($destination) after function($q):
$destinations = $request['destinations'];
if($request->has('destinations'))
{
$trips = Trip::where('status','=',1)->whereHas('destinations', function($q) use($destinations) {
$q->where('destinationsid', '=', $destinations);
})->get();
} else {
echo "No destination provided";
}
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