Search code examples
laravelform-post

Missing required parameters for [Route: patients.destroy] [URI: {language}/patients/{patient}]. (resources/views/patient/index.blade.php)


This is my code of index.blade.php I tried everything with `app()->getLocale() but unfortunately with no positive result. How can i fix it ?

<form action="{{ route('patients.destroy', $patient->id) }}" method="post" style="float: right;">
@csrf
@method('DELETE')
<button type="submit" style="border: 0; background: none; cursor: pointer;"><i class="fa fa-trash"></i></button>
</form>
Route::redirect('/', '/en');
 Route::group(['prefix' => '{language}'], function() { 
        Route::get('/', function () { 
            return view('welcome'); 
        }); 
        Auth::routes(); 
        Route::get('/home', 'HomeController@index')->name('home'); 
        Route::resource('patients', 'PatientController'); 
        Route::get('/search', 'PatientController@search'); 
    });

Solution

  • Your route is expecting two params, and you passed only one so change your route as below.

    <form action="{{ route('patients.destroy', ['language'=>'en','id'=>$patient->id]) }}" method="post" style="float: right;">
    

    Edit:-

    For welcome blade you directly access the URL <a href="{{ url('en') }}"

    Or if you want to do it with route then you need to assign the name as below

    Route::get('/', function () { 
       return view('welcome'); 
    })->name('welcome');
    <a href="{{ route('welcome',app()->getLocale ()) }}"></a>