boot() public static méthode

public static boot ( )
Exemple #1
0
 /**
  * Boot the model.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::deleted(function (Group $group) {
         $group->raise(new GroupWasDeleted($group));
         $group->permissions()->delete();
     });
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public static function boot()
 {
     parent::boot();
     static::deleted(function ($tag) {
         $tag->discussions()->detach();
         Permission::where('permission', 'like', "tag{$tag->id}.%")->delete();
     });
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public static function boot()
 {
     parent::boot();
     // When a post is created, set its type according to the value of the
     // subclass. Also give it an auto-incrementing number within the
     // discussion.
     static::creating(function (Post $post) {
         $post->type = $post::$type;
         $post->number = ++$post->discussion->number_index;
         $post->discussion->save();
     });
     static::deleted(function (Post $post) {
         $post->raise(new PostWasDeleted($post));
     });
     static::addGlobalScope(new RegisteredTypesScope());
 }
Exemple #4
0
 /**
  * Boot the model.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::deleted(function ($discussion) {
         $discussion->raise(new DiscussionWasDeleted($discussion));
         // Delete all of the posts in the discussion. Before we delete them
         // in a big batch query, we will loop through them and raise a
         // PostWasDeleted event for each post.
         $posts = $discussion->posts()->allTypes();
         foreach ($posts->get() as $post) {
             $discussion->raise(new PostWasDeleted($post));
         }
         $posts->delete();
         // Delete all of the 'state' records for all of the users who have
         // read the discussion.
         $discussion->readers()->detach();
     });
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public static function boot()
 {
     parent::boot();
     // When a post is created, set its type according to the value of the
     // subclass. Also give it an auto-incrementing number within the
     // discussion.
     static::creating(function (Post $post) {
         $post->type = $post::$type;
         $post->number = ++$post->discussion->number_index;
         $post->discussion->save();
     });
     // Don't allow the first post in a discussion to be deleted, because
     // it doesn't make sense. The discussion must be deleted instead.
     static::deleting(function (Post $post) {
         if ($post->number == 1) {
             throw new DomainException('Cannot delete the first post of a discussion');
         }
     });
     static::deleted(function (Post $post) {
         $post->raise(new PostWasDeleted($post));
     });
     static::addGlobalScope(new RegisteredTypesScope());
 }
Exemple #6
0
 /**
  * Boot the model.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     // Don't allow the root admin to be deleted.
     static::deleting(function (User $user) {
         if ($user->id == 1) {
             throw new DomainException('Cannot delete the root admin');
         }
     });
     static::deleted(function (User $user) {
         $user->raise(new UserWasDeleted($user));
         // Delete all of the posts by the user. Before we delete them
         // in a big batch query, we will loop through them and raise a
         // PostWasDeleted event for each post.
         $posts = $user->posts()->allTypes();
         foreach ($posts->get() as $post) {
             $user->raise(new PostWasDeleted($post));
         }
         $posts->delete();
         $user->read()->detach();
         $user->groups()->detach();
         $user->accessTokens()->delete();
         $user->notifications()->delete();
     });
     static::$dispatcher->fire(new ConfigureUserPreferences());
 }