Reputation: 93
I have a problem in my resource controller. When I am try to get the row to delete record with destroy
function like I described below it does not work.
public function destroy(SubCategory $subCategory)
{
$subCategory->delete();
}
but if I try some thing like below, it works
public function destroy($subCategory)
{
SubCategory::find($subCategory)->delete();
}
I just want to do that with the first one, I do not know why it's not working?
Upvotes: 2
Views: 145
Reputation: 93
I found an error in my web.php file.It's my mistake I define my resource route like that
Route::resource('subcategory', 'SubCategoryController');
but it should be like below
Route::resource('subCategory', 'SubCategoryController');
Upvotes: 0
Reputation: 19372
Try to define Your model in RouteServiceProvider
or directly on routes.php
file before resource directive:
public function boot(Router $router)
{
parent::boot($router);
Route::model('subCategory', App\SubCategory::class);
}
read about: explicit binding
Upvotes: 1