افصل الكود باستخدام الأحداث:
إنشاء حدث
class OrderPlaced
{
public function __construct(public Order $order) {}
}إنشاء مستمع
class SendOrderConfirmation
{
public function handle(OrderPlaced $event)
{
Mail::to($event->order->user)->send(new OrderConfirmationMail($event->order));
}
}إطلاق الحدث
OrderPlaced::dispatch($order);
event(new OrderPlaced($order));التسجيل في EventServiceProvider
protected $listen = [
OrderPlaced::class => [
SendOrderConfirmation::class,
UpdateInventory::class,
],
];