I have a simple view, which displays results of a query
$number = 5;
$events = Event1::has('users', '<', 1)->latest()->take($number)->get();
TASK: Now I want to create some filter and sorting methods... and be able to refresh the displayed results without page reload
In my view file I have this:
<div id="top5-list">
@foreach($events as $event)
///
@endforeach
</div>
**
TO DO
** I wish to implement the below scenarios, if possible working in the same VIEW:
SCENARIO 1) using the same query, but change the value of parameters - just like in the example above - the variable $number changes the number of displayed results.
Most preferably I'd wish to use more than one variable
SCENARIO 2) build a separate query for each user-selectable viewing mode - for example
filter named: show top - refreshes the content with this query:
$events = Event1::has('users', '<', 1)->latest()->take($number)->get();
and filter named show best - refreshes the content with results of this completely rebuilt query:
$events = Event1::whereHas('users', function($q){
$q->where('importance', 0);})->get();
Scenario 2-A
In one view I will have a top-10 list of more than one item, for example TOP 5 EVENTS and TOP 5 ENTITIES side by side
My desired function: by pressing a button the queries responsible for displaying the top-5 would be changed from, for instance switching from "top-5-most important"
$events = ...query_1...
$entities = ...query_1...
into "top-5-most popular"
$events = ...query_2...
$entities = ...query_2...
SCENARIO 3) My ltimate goal is to build a filter which might sort out Books on-the-fly by clicking none, one, or many genres. Just as my other question demonstrates: how to filter records filtered by more than one criterion in pivot table - laravel eloquent collections