Search code examples
laraveldropdown

How to get a value from a dropdown and the value will be automatically pass to another form?


I have a dropdown button for my table. Each rows has dropdowns. So after I select the NEW option in my dropdown button, it will redirect to my route /link. How to the pass the purchase_group_id to my /link form?

I'm new to laravel. thanks

<button class="btn btn-secondary dropdown-toggle btn-sm" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">ADD MEMBER</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" name="purchase_group_id"href="/link" value="{{$product->purchase_group_id}}" type="submit">NEW</a>
<a class="dropdown-item" href="#">RENEWAL</a>
</div></div>```

Solution

  • First, you must make a route that has a parameter on it like this :

    Route::get('/link/{purchase_group_id}, 'YourController@index');
    

    Then you can use your route link this :

    <a class="dropdown-item" name="purchase_group_id" href="/link/{{$product->purchase_group_id}}" type="submit">NEW</a>
    

    In your controller pass the parameter to next form :

    public function index($purchase_group_id)
    {
        return view('next_form')->with(compact('purchase_group_id'));
    }
    

    Then in your view, you can use $purchase_group_id variable for your form.