i have index page with a button to remove a column from a table.
@foreach ($suppliers as $supplier) <tr> <th>{{ $supplier -> idSupplier }}</th> <th style="color:blue;"><a href="/suppliers/{{$supplier->idSupplier}}">{{ $supplier -> column1 }}</a></th> <th>{{ $supplier -> column2 }}</th> <th>{{ $supplier -> column3 }}</th> <th>{!! $supplier -> column4 !!}</th> <th> <a class="btn btn-warning" href="/suppliers/{{$supplier->idSupplier}}/edit" role="button"> <i class="fa fa-tools"></i> Edit</a> <a class="btn btn-danger" href="{{ action('SuppliersController@destroy') }}" role="button"> <i class="fa fa-eraser"></i> Delete</a> </th> </tr> @endforeach
but now everytime i open my index page it gives me this error message
FacadeIgnitionExceptionsViewException Missing required parameters for [Route: suppliers.destroy] [URI: suppliers/{supplier}]. (View: C:xampphtdocsInventresourcesviewssuppliersindex.blade.php)
this is my route
Route::resource('suppliers', 'SuppliersController');
and this is destroy
function from SuppliersController
public function destroy($idSupplier) { $supplier = Supplier::find($idSupplier); $supplier->delete(); return redirect('/suppliers')->with('success', 'Supplier removed'); }
I already try this solution and it gives me another error message.
Advertisement
Answer
well you are not passing the required parameter for the controller’s action. destroy
method receives a parameter idSupplier
to perform its actions. from blade you are just calling the controller action without passing the parameter. make it like below:
<a class="btn btn-danger" href="{{ action('SuppliersController@destroy', ['idSupplier' => $supplier->idSupplier]) }}" role="button"> <i class="fa fa-eraser"></i> Delete </a>
but it won’t work. your registered route method is DELETE
but it will redirect to a GET
method. So use the follwing method for deleting.
<form action="{{ route('suppliers.destroy', $supplier->idSupplier) }}" method="POST"> @csrf @method('DELETE') <button class="btn btn-danger btn-sm" title="Delete">Delete</button> </form>