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

dmytroshved's avatar

Problem with 2 level dependent dropdown in Livewire 3

I have a problem with my 2 level dependent dropdown.

Dropdown at the page: https://i.ibb.co/d4PBYFcz/5904325373724837675.jpg

After I enter data into the selectors, I am taken to another page, but after returning to the previous page, my component appears to be broken

The problem is that when I go back from recipes.blade.php (2nd page) to index.blade.php (1st page) my component stops working normally (in place of dishes selector I see just an empty white field, there is nothing there), in the other selectors remain the previously selected data. By design, if I return to the index.blade.php page, the component should be clean. Maybe someone has encountered such a problem?

Dropdown after problem: https://i.ibb.co/XZYS2S6p/5904325373724837678.jpg

view:

Filter.php:

1 like
12 replies
vincent15000's avatar

Hello, are you french ? (I am) ... I see some classes like Cuisine and Menu in your code.

Hmmm ... first I would try to check the content of the $dishes variable with a simple @dump($dishes) in the blade view.

Hmmm ... pour commencer je vérifierais le contenu de la variable $dishes avec un simple @duompe($dishes) dans la vue blade.

1 like
Snapey's avatar

@vincent15000 Hi Vincent. Cuisine and Menu are french words that have been absorbed into the english language Like cafe and gateaux.

2 likes
dmytroshved's avatar

@vincent15000 So I've added @dump($dishCategories) and @dump($dishes) into my view. I've prepaired some images so it'll look more clear

1. Fresh selector (https://i.ibb.co/2YHw7Vw1/fresh-selector.jpg)

Illuminate\Database\Eloquent\Collection {#1051 ▼ // resources\views/livewire/filter.blade.php
  #items: array:13 [▶]
  #escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#1960 ▼ // resources\views/livewire/filter.blade.php
  #items: []
  #escapeWhenCastingToString: false
}

2. Selectors with data (https://i.ibb.co/pB4fLXXF/selector-with-data.jpg)

Illuminate\Database\Eloquent\Collection {#1126 // resources\views/livewire/filter.blade.php
  #items: array:13 []
  #escapeWhenCastingToString: false
}
Illuminate\Database\Eloquent\Collection {#1133 // resources\views/livewire/filter.blade.php
  #items: array:1 []
  #escapeWhenCastingToString: false
}

3. After redirect to another page (https://i.ibb.co/VYk1YNBC/after-redirect.jpg). I also added dump($request); to my FilterController to debug query parameters from form with selectors:

Illuminate\Database\Eloquent\Collection {#935 ▼ // resources\views/livewire/filter.blade.php
  #items: array:13 [▶]
  #escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#1868 ▼ // resources\views/livewire/filter.blade.php
  #items: []
  #escapeWhenCastingToString: false
}

FilterController.php:

class FilterController extends Controller
{
    public  function filter(Request $request)
    {
        dump($request);

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

4. And after returning to the previous page I see the problem (https://i.ibb.co/pvN5j3tR/problem-again.jpg)

Illuminate\Database\Eloquent\Collection {#1051 ▼ // resources\views/livewire/filter.blade.php
  #items: array:13 [▶]
  #escapeWhenCastingToString: false
}
Illuminate\Support\Collection {#1960 ▼ // resources\views/livewire/filter.blade.php
  #items: []
  #escapeWhenCastingToString: false
}
1 like
vincent15000's avatar

@Dmytro_Shved Hmmm ... are you really redirecting to another page ?

After redirect to another page

Where is this redirection in your code ?

And after returning to the previous page I see the problem

How do you return to the previous page ?

vincent15000's avatar

@Snapey Oh great ;) ... I didn't know ... like basket, foot, dressing, ... into the french language ;) ... even though dressing has a completely different definition in french.

dmytroshved's avatar

@vincent15000 I am redirecting to page recipes.blade.php using form button:

<!-- Filter button -->
        <div class="...">
            <button type="submit" class="..."> Filter </button>
        </div>

and this form action looks like this:

<form action="{{ route('filter') }}" method="GET">

And here is my route:

Route::get('/recipes', [FilterController::class, 'filter'])->name('filter');

I go back to the previous page using the arrows in the browser

1 like
dmytroshved's avatar

@vincent15000 How do I proceed if I go back to the previous page using the arrows in the browser (and I think the component is breaking because of the browser cache)

1 like
vincent15000's avatar

@Dmytro_Shved I get some similar errors when using the arrows in the browser. I don't have found how to solve this problem.

Are you using Livewire v2 or v3 ? If v3, are you using computed properties ?

1 like
dmytroshved's avatar

@vincent15000 I am using livewire 3.

I also tried computed properties, but actually it was a start point with my problem, after that I tried 2-3 different code logic but I got same problem.

I've never encountered anything like this.

And I was suprised that nobody uses depending dropdowns in filter (at least I didn’t find such a video where someone would do similar code)

1 like
dmytroshved's avatar

@vincent15000 Additionally, when I am turning off Caching in F12 -> Network -> 'Disable cache' it solves the problem, but I can’t just disable the cache for the entire site; in any case, the user will use it so as not to reload pages every time

1 like
dmytroshved's avatar
dmytroshved
OP
Best Answer
Level 6

Hello @vincent15000

I found a solution! I have added autocomplete="off" attribute to my <select> and It's working!

The problem was in the browser autocomplete the form

Now after returning to previous page using arrow back in browser my selectors are clear!

1 like

Please or to participate in this conversation.