Exemplo n.º 1
0
 public static function boot()
 {
     parent::boot();
     static::created(function ($topic) {
         SiteStatus::newUser();
     });
 }
 /**
  * Attach a listener to the 'deleted' event.
  */
 public static function boot()
 {
     parent::boot();
     // Adjust the order of the other roles on delete
     static::deleted(function ($role) {
         $adjust_roles = static::where('order', '>', $role->order)->get();
         foreach ($adjust_roles as $r) {
             $r->order--;
             $r->save();
         }
     });
 }
Exemplo n.º 3
0
 public static function boot()
 {
     // NOTE saving   -> creating -> created   -> saved
     // NOTE saving   -> updating -> updated   -> saved
     // NOTE deleting -> deleted  -> restoring -> restored
     // updating BEFORE validation
     static::updating(function ($account) {
         // Updating user or provider is not allowed
         $account->restoreOriginalAttributes('provider_id', 'user_id');
     });
     parent::boot();
     // Validate the model
 }
Exemplo n.º 4
0
 public static function boot()
 {
     // NOTE saving   -> creating -> created   -> saved
     // NOTE saving   -> updating -> updated   -> saved
     // NOTE deleting -> deleted  -> restoring -> restored
     parent::boot();
     // Validate the model
     static::saved(function ($doc) {
         Profile::purgeDocumentsCache();
     });
     static::deleted(function ($doc) {
         Profile::purgeDocumentsCache();
     });
     static::restored(function ($doc) {
         Profile::purgeDocumentsCache();
     });
 }
Exemplo n.º 5
0
 public static function boot()
 {
     // NOTE saving   -> creating -> created   -> saved
     // NOTE saving   -> updating -> updated   -> saved
     // NOTE deleting -> deleted  -> restoring -> restored
     parent::boot();
     // Validate the model
     static::saved(function ($profile) {
         // Purge permissions cache
         Cache::forget("profile{$profile->id}permissions");
     });
     static::deleted(function ($profile) {
         // Purge permissions and documents cache
         Cache::forget("profile{$profile->id}permissions");
         Cache::forget("profile{$profile->id}documents");
     });
 }
Exemplo n.º 6
0
 public static function boot()
 {
     // NOTE saving   -> creating -> created   -> saved
     // NOTE saving   -> updating -> updated   -> saved
     // NOTE deleting -> deleted  -> restoring -> restored
     parent::boot();
     // Validate the model
     static::saved(function ($language) {
         // Only one Language can be the default
         if ($language->is_default) {
             Language::where('id', '<>', $language->id)->update(['is_default' => 0]);
         }
         // Purge cache
         Cache::forget('allLanguagesOrderedByPriority');
     });
     static::deleted(function ($language) {
         // Purge cache
         Cache::forget('allLanguagesOrderedByPriority');
     });
     static::restored(function ($language) {
         // Purge cache
         Cache::forget('allLanguagesOrderedByPriority');
     });
 }
Exemplo n.º 7
0
 public static function boot()
 {
     // NOTE saving   -> creating -> created   -> saved
     // NOTE saving   -> updating -> updated   -> saved
     // NOTE deleting -> deleted  -> restoring -> restored
     // updating BEFORE validation
     static::updating(function ($user) {
         // When updating, password is not required.
         if (!strlen($user->convertEmptyAttributesToNull()->password)) {
             $user->removeRule('password', 'required|confirmed');
             $user->restoreOriginalAttributes('password');
         }
     });
     // restoring BEFORE validation
     static::restoring(function ($user) {
         $user->removeRule('password', 'required|confirmed');
     });
     parent::boot();
     // Validate the model
     static::saving(function ($user) {
         // Make sure profile is similar or inferior
         if (auth()->check() and auth()->user()->id !== 1 and !auth()->user()->profile->getSimilarOrInferior()->contains($user->profile_id)) {
             throw new ModelValidationException(_('Profile must be similar or inferior to your own profile'));
         }
     });
     static::creating(function ($user) {
         // Hash password if not hashed
         $user->hashPassword();
     });
     static::created(function ($user) {
         // If the user has no Laravel account, create it
         if (!$user->accounts()->where('provider_id', 1)->first()) {
             Account::create(['uid' => $user->id, 'nickname' => $user->username, 'name' => $user->name, 'provider_id' => 1, 'user_id' => $user->id]);
         }
     });
     static::updating(function ($user) {
         // Hash password if not hashed
         $user->hashPassword();
     });
     static::updated(function ($user) {
         // If we have updated current user then change application language accordingly
         if (auth()->check() and auth()->user()->id == $user->id) {
             $user->applyLanguage();
         }
     });
     static::deleted(function ($user) {
         // Purge cache
         Cache::forget("adminSearchResults{$user->id}");
     });
 }