laravelinputlaravel-bladeroute-parameters

How to get the selected value from a group select in Blade?


Is there a way one can access the value of a group select in order to use it as a parameter in a route?

This is the html element:

<div class="flex justify-center mt-5">
    <div class="form-control" >
        <div class="input-group">
        <select class="select select-bordered" name="search">
            <option disabled selected>Select</option>
            <option>Visits</option>
            <option>Visitors</option>
        </select>
        <a class="btn" href="">Search</a>        
        </div>
    </div>
</div>

This is the route:

Route::get('/search/{search}', [SearchController::class, 'show_resource'])
    ->middleware('auth')
    ->name('search_resource');

What I am trying to do without success is to pass the selected value to the href attribute of the link, something like this:

<a class="btn" href="{{ search('search_resource', 'search' => $inputValue)}}">Search</a>  

Solution

  • Use Ajax and jquery you can do something like this:

    function get_search(){
        var search= $("select[name='search']").val();
    
        $.ajax({
            url:"{{route('/search/')}} + search",
            type:'GET',
            success: function(result){
                console.log(result);
               $('#your_div').html(result);
            }
        });
    }