Skip to content
Advertisement

Search for an item using a dropdown list in Laravel that returns the results onto a view

I’m trying to search for the items that are listed in the dropdown list, however I seem to get this error Controller@action not defined however in the web.php I have defined that controller so I’m not sure why that error is occurring. So I can’t test to see if the query in controller is returning the correct results. Thank you.

Web.php

Route::get('/','FrontendControllersHomeController@index', function () {
    return view('Frontend::index');
});


Route::group(['module' => 'Frontend', 'middleware' => ['web'], 'namespace' => 'FrontendControllers'], function() {

    // Page Routes
    Route::get('/result', 'HomeController@search')->name('search');
    Route::resource('home', 'HomeController');

    Route::get('/vehicles', 'PressController@index')->name('press');
    Route::get('vehicles/{slug}', 'PressController@show')->name('press.show');
    Route::get('/about-us', 'AboutController@index')->name('about');
    Route::get('/benefits', 'BenefitsController@index')->name('benefits');
    Route::get('/partners', 'PartnersController@index')->name('partners');
    Route::get('/contact-us', 'ContactController@index')->name('contact');
    Route::get('/register', 'RegisterController@index')->name('register');
    Route::get('/privacy-policy', 'PrivacyController@index')->name('privacy');
    Route::get('/terms-conditions', 'TermsController@index')->name('terms');
});

Blade

<form method="get" action="{{ action('HomeController@search') }}" enctype="multipart/form-data">
    <div class="md-form">
        <label style="font-weight: 600; display: contents;" for="form2" class="active white-text">Vehicles in stock</label>
        <select style="margin-top: 0.5rem;" class="form-control search-form-control white-text">
            <option value="volvo">Any vehicle...</option>
            @foreach($posts as $post)
                <option id="{{$post->id}}" value="volvo">{{$post->vehicle}} {{$post->h1}}</option>
            @endforeach
        </select>
    </div>

    <div class="text-center mt-4">
        <button style="background-color: #2d3e50!important;" class="btn btn-indigo">Search</button>
        <hr class="mb-3 mt-4 hr-light">
        <div class="inline-ul text-center">
            <a class="p-2 m-2 li-ic">
                <i class="fab fa-linkedin-in white-text"> </i>
            </a>
            <a class="p-2 m-2 ins-ic">
                <i class="fab fa-facebook-f white-text"> </i>
            </a>
        </div>
    </div>
</form>

Controller

public function search(Request $request)
{
    $post = Post::where('id', $request->id)->get();

    return view('Frontend::pages.press.show', compact('post'));
}

Advertisement

Answer

It seems you are using a modules package so use the controller and action names along with the namespace something like:

{{ action('BrandonModulesFrontendControllersHomeController@search') }}

Or just do:

{{ route('search') }}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement