I need to create a logic for my page with filtered recipes with ability to sort them by date
Current code
RecipeController gives me $recipes it is a collection with filtered recipes (params for filter are from URL):
class RecipeController extends Controller
{
public function index(RecipeFilterRequest $request)
{
// ...after filtration logic => $recipes
return view('recipes.recipes', compact('recipes'));
}
}
And then in recipes/recipes.blade.php:
@foreach($recipes as $recipe)
<x-recipe-card :recipe="$recipe"/>
@endforeach
components/recipe-card.blade.php is basically a card with recipe info
What I want to achieve:
I need to create a logic for dropdown filter that will sort list of filtered recipes by date added
It looks like this: https://i.ibb.co/wrrffZVK/sort-dropdown.jpg
My suggestion:
Make an extra livewire component livewire/recipes-list.blade.php(RecipesList.php) and in recipes.blade.php use this livewire component for the list of (filtered in RecipeController) recipes .
and I’ll basically do everything in this order:
RecipeController =(passing $recipes)=> recipes.blade.php =(passing $recipes to livewire component)=> livewire/recipes-list.blade.php
and in livewire/recipes-list.blade.php I’ll add logic for this dropdown
What do you think?
Has anyone done anything similar/exactly the same?
Would be grateful for some advices


