Esempio n. 1
0
 /**
  * Observers
  */
 public static function boot()
 {
     parent::boot();
     $self = __CLASS__;
     static::creating(function ($model) use($self) {
         // slug = null si vide
         $slug = $model->slug ? $model->slug : null;
         $model->slug = $slug;
         if ($slug) {
             $i = 0;
             // Check uri is unique
             while ($self::where('slug', $model->slug)->first()) {
                 $i++;
                 // increment slug if exists
                 $model->slug = $slug . '-' . $i;
             }
         }
     });
     static::updating(function ($model) use($self) {
         // slug = null si vide
         $slug = $model->slug ? $model->slug : null;
         $model->slug = $slug;
         if ($slug) {
             $i = 0;
             // Check uri is unique
             while ($self::where('slug', $model->slug)->where('id', '!=', $model->id)->first()) {
                 $i++;
                 // increment slug if exists
                 $model->slug = $slug . '-' . $i;
             }
         }
     });
 }
Esempio n. 2
0
 /**
  * Observers
  */
 public static function boot()
 {
     parent::boot();
     static::deleted(function (File $model) {
         Croppa::delete($model->path . '/' . $model->filename);
     });
 }
Esempio n. 3
0
 /**
  * Observers
  */
 public static function boot()
 {
     parent::boot();
     static::creating(function (Page $model) {
         // set is_home = 0 on previous homepage
         if ($model->is_home) {
             static::where('is_home', 1)->update(array('is_home' => 0));
         }
     });
     static::updating(function (Page $model) {
         // set is_home = 0 on previous homepage
         if ($model->is_home) {
             static::where('is_home', 1)->where('id', '!=', $model->id)->update(array('is_home' => 0));
         }
     });
 }