Illuminate\Database\Eloquent\Model::fireModelEvent PHP Method

fireModelEvent() protected method

Fire the given event for the model.
protected fireModelEvent ( string $event, boolean $halt = true ) : mixed
$event string
$halt boolean
return mixed
    protected function fireModelEvent($event, $halt = true)
    {
        if (!isset(static::$dispatcher)) {
            return true;
        }
        $method = $halt ? 'until' : 'fire';
        // If a custom event type has been configured for this event we'll fire that
        // instead of the string version of the event. This provides for a custom
        // "object-based" event more consistent with the rest of the framework.
        if (isset($this->events[$event])) {
            $result = static::$dispatcher->{$method}(new $this->events[$event]($this));
            if (!is_null($result)) {
                return $result;
            }
        }
        // We will append the names of the class to the event to distinguish it from
        // other model events that are fired, allowing us to listen on each model
        // event set individually instead of catching event for all the models.
        $event = "eloquent.{$event}: " . static::class;
        return static::$dispatcher->{$method}($event, $this);
    }

Usage Example

Example #1
0
 /**
  * Event trigger. For manually triggering model events.
  */
 public function fireEvent($event)
 {
     $halt = ends_with($event, 'ing');
     return parent::fireModelEvent($event, $halt);
 }
Model