1

Can't delete product with any method combination. Tried with <form>, Laravel Collective Form::, and others.

I've looked around and there is similar issues like mine and none of the answers have solved my issue yet. Made several combinations.

View:

<form action="{{ route ('inventory.destroy', [$item->id])}}" method="POST">
    @csrf
    @method('delete')
    <button class="btn btn-danger btn-sm" type="submit">
        Eliminar
    </button>
</form>

Route:

Route::delete('/delete/{$id}', 'ProductController@destroy')->name('inventory.destroy')->middleware('auth');

Controller:

public function destroy($id)
    {
        $product = Product::findOrFail($id);
        $product->delete();

        return redirect('/inventory')->with('success', 'producto eliminado');
    }

Delete button will always (by any method) take me to /delete/{id} instead of /inventory and throw a 404.

Also tried with these two and haven't had luck yet:

{!! Form::open(['action' => ['ProductController@destroy', $item->id], 'method' => 'delete'])!!}
    {{ Form::hidden('_method','DELETE')}}
    {{Form::submit('Eliminar', ['class'=>'btn btn-danger'])}}
{!! Form::close()!!}

and

<form action="{{ url('/delete', ['id' => $item->id]) }}" method="POST">
    <input class="btn btn-danger" type="submit" value="Delete">
    @method('delete')
    @csrf
</form>

I don't want to be repetitive but I can't get this work.

Don't Panic
  • 13,965
  • 5
  • 32
  • 51
Fer Toasted
  • 1,274
  • 1
  • 11
  • 27

0 Answers0