Search code examples
phplaraveleloquentormweb-frameworks

Route [proforms2.destroy2] not defined


I wan't to make second destroy method in my controller, to delete part of bigger deletable element. I've got error in view on this line:

 `<td><form action="{{ route('proforms2.destroy2',$query2->id) }}" method="POST"></td>`

Route [proforms2.destroy2] not defined.

This is route:

`Route::resource('proforms2', 'ProformController@destroy2');`

This is ProformController.php method:

public function destroy2(Proform $proform, $query2)
{
$query2->delete();

return redirect()->route('proforms.edit')
->with('success','Product deleted successfully');
}

Solution

  • you don't need to use a method call when you are using laravel Resource. you can do something like below:

    Route::get('delete/proforms/{preform}','ProformController@destroy2')->name('proforms2.destroy2');
    

    and in the controller method as below

        public function destroy2(Proform $proform)
    {
    $proform->delete();
    
    return redirect()->route('proforms.edit')
    ->with('success','Product deleted successfully');
    }
    

    i may missed something but you can do something like that.