I'm using Laravel's Event & Listener functionality to detect the following model actions and trigger some application logic.
app/models/MealFood
/**
* The event map for the model.
*
* Allows for object-based events for native Eloquent events.
*
* @var array
*/
protected $dispatchesEvents = [
'created' => MealFoodEvent::class,
'updated' => MealFoodEvent::class,
'deleted' => MealFoodEvent::class
];
app/events/MealFoodEvent
public $mealFood;
/**
* Create a new event instance.
*
* @param MealFood $mealFood
*/
public function __construct(MealFood $mealFood)
{
$this->mealFood = $mealFood;
}
app/listeners/MealFoodListener
public function handle(MealFoodEvent $event)
{
$mealFood = $event->mealFood;
}
Is it possible to detect what model action triggered the event? I want to be able to know if the record triggering the event was created/updated/deleted. Right know I'm using soft deletes to check if the record was deleted but how can I know if the record was updated or created?