Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dmytroshved's avatar

Question about sort dropdown for sorting recipes by date in Livewire

Hey everyone

This question is theoretical, I just wanna to gain some approaches to achieving this task

How does my code/views look in the project:

I have a filter that shows me a page with list of filtered recipes:

RecipeController

class RecipeController extends Controller
{
    public function index(RecipeFilterRequest $request)
    {
        // ...filtration logic => $recipes

        return view('recipes.recipes', compact('recipes'));
    }

recipes.blade.php:

            @foreach($recipes as $recipe)
                <x-recipe-card :recipe="$recipe"/>
            @endforeach

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

Has anyone done anything similar/exactly the same?

Would be grateful for some advices


EDIT 01:

Here's my suggestion:

Make an extra livewire component livewire/recipes-list.blade.php with a class RecipesList.php

and I'll basically do everything in this order:

RecipeController =(passing $recipes)=> recipes.blade.php =(passing to livewire component $recipes)=> livewire/recipes-list.blade.php

and in livewire/recipes-list.blade.php I'll add logic for this dropdown

What do you think?

1 like
1 reply

Please or to participate in this conversation.