$events=Event::all();
if (isset($scheduling) && $scheduling!=="All")
{
$events = $events->filter(function($event) use ($scheduling)
{
return $event->where('scheduling',$scheduling);
});
}
$events=$events->get();
can some one correct this code. the inner filter is not working. the results are same with or without applying filters. i need to apply lot filters like this basing on conditions
The filter query parameters can be used to add where clauses to your Eloquent query. Out of the box we support filtering results by partial attribute value, exact attribute value or even if an attribute value exists in a given array of values. For anything more advanced, custom filters can be used.
Laravel Pluck() is a Laravel Collections method used to extract certain values from the collection. You might often would want to extract certain data from the collection i.e Eloquent collection.
You don't have to use where condition in it, you can just return true
or false
from within callback
, depending on the selection condition.
Below code will keep only those events
that pass a given truth test:
$events=Event::all();
if (isset($scheduling) && $scheduling!=="All")
{
$events = $events->filter(function($event) use ($scheduling)
{
return $event->scheduling == $scheduling;
});
}
dd($events); //Collection
Read More
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