Filtering query results with different conditions on the same page
Title of the article might sound unclear, but let's imagine you have customer list from Customer::all(), but then you need two separate lists/tables - customers from UK and from US. How to avoid two queries here? There's a filter() function.
So, you're doing like this as usual:
$customers = Customer::all();
And then you can filter the results, passing your own closure function to describe condition.
So, now you have two separate lists in $uk_customers and $us_customers and you can view them in separate tables.
There's also an opposite function called reject() - for example, if you want to keep all records EXCEPT United Kingdom, this is how it would look: