简体   繁体   中英

Laravel - get data from input field not working

i'm having trouble to get data from an input.

I try to be more specific

My application has many views, and each of these has an @include component that works as a search field. For example the user types in the input the ID of the store, the controller compares the ID that user inserted with the DB store's ID and then compacts data and fill the views with infos of that specific store. Im just testing how to get that data from the input but i'm getting this error:

Route [search.get_kcli] not defined.

Actually i'm trying to use that function only for get data by using a controller only for that input field.

What's wrong in it? Thanks for help!

My code looks like this:

inside of app.blade.php

        @auth
            @include('partials.search')
        @endauth

inside search.blade.php

 <form method="POST" class="form-inline position-relative"
     action="{{ route('search.get_kcli') }}">
    @csrf
    @method('POST')
  <input class="form-control shadow-none" name="kcli" id="kcli" type="number" 
         placeholder="Codice..." aria-label="Search">
  <button type="submit" class="btn btn-light search-btn"><i class="fas fa-search"></i></button>
</form>

Inside the SearchController.php

<?php

     namespace App\Http\Controllers;
     use Illuminate\Support\Facades\DB;
     use Illuminate\Http\Request;

     class SearchController extends Controller
     {
            function get_kcli(Request $request) {
    
               $kcli = $request->input('kcli');
               dd($kcli);
}

}

Inside web.php

Route::post('/search', [App\Http\Controllers\SearchController::class, 'get_kcli'])->name('search');

Change

<form method="POST" class="form-inline position-relative"
     action="{{ route('search.get_kcli') }}">

to

<form method="POST" class="form-inline position-relative"
     action="{{ route('search') }}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM