Company. The company has one-to-many products. When you delete a company, you must delete all related products and their images ! The goods themselves are deleted from the database as needed, but the event is not picked up (the message "OK" is not displayed)! Tried through Events - also does not work. Through the Observer it looks like this:
Company deletion method:
public function destroy($id) { $company = Company::findOrFail($id); // удаляем связанные товары $company->goods()->delete(); // удаляем компанию $company->delete(); return redirect()->route('...'); } Communication in the company model:
public function goods() { return $this->hasMany('App\Models\Good', 'company_id' , 'id'); } Product removal method:
public function destroy($id) { $good = Good::findOrFail($id); // удаление товара + вызов Observer $good->delete(); return redirect()->route('...'); } Register Observer in AppServiceProvider:
public function boot() { parent::boot(); Good::observe(GoodObserver::class); } Observer code:
class GoodObserver { public function deleting(Good $good) { dd('OK'); // вывод сообщения об удалении } }