1 回答

TA貢獻1794條經驗 獲得超8個贊
請執行下列操作:
php artisan make:observer CategoryObserver
打開
app/Observers/CategoryObserver.php
在
deleting()
方法中,把這個:
//delete the icon
$icon = $destroy_category->icon;
File::delete(public_path($icon));
$destroy_category->delete();
打開app/Provivers/AppServiceProvider.php并將其放在boot()方法中:
Category::observe(CategoryObserver::class); //import the class correctly
將您的控制器代碼更改為:
public function destroy(Request $request , $id)
{
$destroy_category = Categories::find($id);
$destroy_category->delete(); //this will fire the CategoryObserver::deleting() method
return redirect('/category/index')->with('success' , 'Category Deleted Successfully');
}
- 1 回答
- 0 關注
- 92 瀏覽
添加回答
舉報