Illuminate\Routing\Exceptions\UrlGenerationException Missing required parameters for [Route: products] [URI: products/delete/{id}]

Viewed 1095

This is My route in the file of Web.php

What I am doing wrong?

 Route::get('/products/delete/{id}',[ProductsController::class, 'delete'])->name('products');

This is my product blade file

 <a href="products/delete/{{$product->id}}">Delete</a>

Here is My Product Controller Function

public function delete($id)
{
    $product=Product::find($id);
    $product->delete();
    return redirect()->route('products');
}
2 Answers

I think you should use

return redirect()->back()

Or redirect to any other route instead to redirect to same route

//Its working Correctly after changes in my Routs and paths and functions 
//I change in my blade file

<a href="products/delete/{{$product->id}}">Delete</a>

//This is My route in the file of Web.php (i made change in my Route::get)


Route::get('products/delete/{id}',[ProductsController::class, 'delete']);

//Here is My Product Controller Function (Made Litte changes)

public function delete($id)
    {
        $product=Product::findorfail($id);
        if($product){
            $product->delete();
            return back()->with('deleted', "Record Deleted Successfully");
        }else{
            return back()->with('Error', "Record Not Found");
        }

    }
Related