boot() protected static method

We'll use this method to register event listeners on a Node instance as suggested in the beta documentation... TODO: - Find a way to avoid needing to declare the called methods "public" as registering the event listeners *inside* this methods does not give us an object context. Events: 1. "creating": Before creating a new Node we'll assign a default value for the left and right indexes. 2. "saving": Before saving, we'll perform a check to see if we have to move to another parent. 3. "saved": Move to the new parent after saving if needed and re-set depth. 4. "deleting": Before delete we should prune all children and update the left and right indexes for the remaining nodes. 5. (optional) "restoring": Before a soft-delete node restore operation, shift its siblings. 6. (optional) "restore": After having restored a soft-deleted node, restore all of its descendants.
protected static boot ( ) : void
return void
Exemplo n.º 1
0
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($cluster) {
         $cluster->ensureUuid();
     });
 }
Exemplo n.º 2
0
 protected static function boot()
 {
     parent::boot();
     static::deleting(function ($model) {
         $model->prepareForDelete();
     });
 }
Exemplo n.º 3
0
 protected static function boot()
 {
     parent::boot();
     // When deleting we should also clean up any relationships
     static::deleting(function ($model) {
         $model->images()->detach();
     });
 }
Exemplo n.º 4
0
 public static function boot()
 {
     parent::boot();
     //        App::register($this->service_provider);
     //we need to fill in all the defaults for this item..
     Content::created(function ($content) {
         //we need check for sub pages and create them!
     });
 }
Exemplo n.º 5
0
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::updating(function ($category) {
         // Baum triggers a parent move, which puts the item last in the list, even if the old and new parents are the same
         if ($category->isParentIdSame()) {
             $category->stopBaumParentMove();
         }
     });
 }
Exemplo n.º 6
0
Arquivo: Menu.php Projeto: zedx/core
 protected static function boot()
 {
     parent::boot();
     static::moved(function ($menu) {
         event(new MenuWasMoved($menu));
     });
     static::deleted(function ($menu) {
         event(new MenuWasDeleted($menu));
     });
 }
Exemplo n.º 7
0
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::updating(function ($navItem) {
         $dirty = $navItem->getDirty();
         $oldNavItem = self::where('id', '=', $navItem->id)->first();
         $oldParent = $oldNavItem->parent;
         $oldParentId = $oldParent->id;
         if (isset($dirty[$navItem->getParentColumnName()]) && $dirty[$navItem->getParentColumnName()] == $oldParentId) {
             unset($navItem->{$navItem->getParentColumnName()});
             static::$moveToNewParentId = FALSE;
         }
     });
 }
Exemplo n.º 8
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         if (Schema::hasColumn($model->getTable(), 'created_at')) {
             $model->created_at = date('Y-m-d H:i:s');
         }
         if (Schema::hasColumn($model->getTable(), 'created_by') && !$model->created_by) {
             $model->created_by = Auth::check() ? Auth::user()->id : 0;
         }
     });
     static::saving(function ($model) {
         if (Schema::hasColumn($model->getTable(), 'updated_by') && !$model->updated_by) {
             $model->updated_by = Auth::check() ? Auth::user()->id : 0;
         }
     });
 }
Exemplo n.º 9
0
 protected static function boot()
 {
     parent::boot();
     static::created(function ($category) {
         event(new CategoryWasCreated($category));
     });
     static::moved(function ($category) {
         event(new CategoryWasMoved($category));
     });
     static::deleted(function ($category) {
         event(new CategoryWasDeleted($category));
     });
     static::deleting(function ($category) {
         foreach ($category->ads as $ad) {
             $ad->forceDelete();
         }
         $category->codes()->delete();
         $category->fields()->detach();
     });
 }
Exemplo n.º 10
0
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     // Do not forget this!
     parent::boot();
     static::moving(function ($node) {
         // YOUR CODE HERE
     });
     static::moved(function ($node) {
         // YOUR CODE HERE
     });
 }
Exemplo n.º 11
0
 protected static function boot()
 {
     parent::boot();
     static::deleting(function ($task) {
         $task->comments()->delete();
         $task->activities()->delete();
         $task->children()->delete();
     });
 }