jeudi 3 décembre 2020

How get old value of select in laravel 8 blade?

I am a beginner in Web and Laravel.I posted the same question yesterday but I delete it, because it is not clear for this I post again with more clarification. I have Select tag and a table, the table values change according to what I selected, When I select item the table is changed each time based on what I selected when I submit the Select all this works fine but the problem here is the Select lost the value I selected and goes back to the first element whose value '-1', please any suggestion to update my code to get the old value of Select after submit. I load the same view twice with the same function the first with get an the second with post :

Route::get('/plaintes/trib', [PlainModelController::class,'suivi']);
Route::post('/plaintes/trib', [PlainModelController::class,'suivi']);

In my controller PlainModelController.php

public function suivi(Request $request)
    {

        $id_user = Auth::id();
        
        $id_cour = explode('/', $id_user)[0];
        
        $id_trib = ($request->choose_trib == "-1") ? $id_cour : $request->choose_trib;
        $tribs = DB::select('SELECT CODE_TRIB as code_trib,
                             DESIG as desig
                             FROM TRIB   
                             WHERE CODE_COUR = ? ORDER BY CODE_TRIB',[$id_cour]);

        //query111 to fill the table it's work fine.

        return view('suivi',compact('plaintes','tribs','id_trib'));
    }

View suivi.blade.php:

<form action="/plaintes/trib" method="POST">
        @csrf
        <label for="choose_trib"> choose trib : </label>
        <select name="choose_trib" id="choose_trib" onchange="this.form.submit()">
            <option value="-1" > choose trib</option>
             @foreach ($tribs as $trib)             
                    <option  value="" > </option>             
            @endforeach
        </select>
    </form>
.....
I fill my table here with query111// It's work fine here.
.....



Aucun commentaire:

Enregistrer un commentaire