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

saving() public static method

Register a saving model event with the dispatcher.
public static saving ( Closure | string $callback, integer $priority ) : void
$callback Closure | string
$priority integer
return void
    public static function saving($callback, $priority = 0)
    {
        static::registerModelEvent('saving', $callback, $priority);
    }

Usage Example

示例#1
0
 /**
  * Setting handlers on save Entity
  */
 public static function boot()
 {
     parent::boot();
     parent::saving(function (Entity $entity) {
         if (!$entity->exists) {
             $entity->family_id = $entity->set->getNewSet();
         }
     });
     parent::created(function (Entity $entity) {
         $entity->closure->insertNode($entity->id);
     });
 }
Model