boot() protected static method

The "booting" method of the model.
protected static boot ( ) : void
return void
Example #1
0
 public static function boot()
 {
     parent::boot();
     static::deleting(function ($medium) {
         \File::delete($medium->path);
     });
 }
Example #2
0
 /**
  * Overrides the models boot method.
  */
 public static function boot()
 {
     parent::boot();
     self::creating(function ($tag) {
         $tag->slug = Str::slug($tag->name);
     });
 }
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->effectivefrom = date('Y-m-d', strtotime($model->effectivefrom));
         $model->effectiveto = date('Y-m-d', strtotime($model->effectiveto));
         $model->createdby = Auth::user()->id;
         $model->createddate = date("Y-m-d H:i:s");
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::created(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Add', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
     });
     static::updating(function ($model) {
         $model->effectivefrom = date('Y-m-d', strtotime($model->effectivefrom));
         $model->effectiveto = date('Y-m-d', strtotime($model->effectiveto));
         $model->modifiedby = Auth::user()->id;
         $model->modifieddate = date("Y-m-d H:i:s");
     });
     static::updated(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Update', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
     });
     static::deleted(function ($model) {
         Log::create(['employeeid' => Auth::user()->id, 'operation' => 'Delete', 'date' => date("Y-m-d H:i:s"), 'model' => class_basename(get_class($model)), 'detail' => $model->toJson()]);
     });
 }
 public static function boot()
 {
     parent::boot();
     ProductReview::deleting(function ($productReview) {
         File::delete($productReview->image);
     });
 }
Example #5
0
 /**
  * Boot the model.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::created(function (self $preset) {
         event(new PresetCreated($preset));
     });
 }
Example #6
0
 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->setCreatedAt($model->freshTimestamp());
     });
 }
Example #7
0
 public static function boot()
 {
     parent::boot();
     Type::creating(function ($type) {
         $type->company_id = $type->company_id ?: Auth::user()['company_id'];
     });
 }
Example #8
0
 public static function boot()
 {
     parent::boot();
     Webhook::creating(function ($results) {
         Cache::forget('webhooks');
     });
 }
Example #9
0
 /**
  * Model bootstrap
  *
  * Ensure that the full_name field is filled even if it isn't initially provided.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         return $model->fillFullName()->fillCompanyName();
     });
 }
 public static function boot()
 {
     parent::boot();
     Event::deleting(function ($event) {
         File::delete($event->image);
     });
 }
Example #11
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         if ($model->status == null) {
             $model->status = static::CREATE;
         }
         if ($model->qty == null) {
             $model->qty = 1;
         }
         if ($model->location_id != null) {
             $location = Location::find($model->location_id, ['name']);
             if ($location) {
                 $model->location_name = $location->name;
             }
         }
     });
     static::created(function ($model) {
     });
     static::updating(function ($model) {
         if ($model->qty == null) {
             $model->qty = 1;
         }
     });
 }
Example #12
0
 public static function boot()
 {
     parent::boot();
     static::deleting(function ($user) {
         $user->profile->delete();
     });
 }
Example #13
0
 /**
  * Listen for save event
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function ($model) {
         self::setNullables($model);
     });
 }
Example #14
0
 /**
  * 删除文章时关联删除评论
  */
 protected static function boot()
 {
     parent::boot();
     static::deleting(function ($article) {
         $article->comment()->delete();
     });
 }
Example #15
0
 public static function boot()
 {
     parent::boot();
     Widget::saved(function ($widget) {
         \Cache::tags('widgets')->flush();
     });
 }
Example #16
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($profile) {
         $profile->profile_pic = asset('img/avatar.png');
     });
 }
Example #17
0
 public static function boot()
 {
     parent::boot();
     static::created(function ($topic) {
         SiteStatus::newReply();
     });
 }
 public static function boot()
 {
     parent::boot();
     CourseGalleryItem::deleting(function ($courseGalleryItem) {
         File::delete($courseGalleryItem->image);
     });
 }
Example #19
0
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->{$model->getKeyName()} = Uuid::generate(4);
     });
 }
Example #20
0
 public static function boot()
 {
     parent::boot();
     static::saving(function ($instance) {
         $instance->code = strtoupper(str_random(6));
     });
 }
Example #21
0
File: Adtype.php Project: zedx/core
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($adtype) {
         event(new AdtypeWillBeCreated($adtype));
     });
     static::created(function ($adtype) {
         event(new AdtypeWasCreated($adtype));
     });
     static::updating(function ($adtype) {
         event(new AdtypeWillBeUpdated($adtype));
     });
     static::updated(function ($adtype) {
         event(new AdtypeWasUpdated($adtype));
     });
     static::deleted(function ($adtype) {
         event(new AdtypeWasDeleted($adtype));
     });
     static::deleting(function ($adtype) {
         event(new AdtypeWillBeDeleted($adtype));
         foreach ($adtype->ads as $ad) {
             $ad->forceDelete();
         }
         $adtype->subscriptions()->detach();
         $adtype->users()->detach();
     });
 }
Example #22
0
 public static function boot()
 {
     parent::boot();
     Category::creating(function (Category $category) {
         $category->generateSlug();
     });
 }
Example #23
0
 /**
  * Listen for save event
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function ($model) {
         return $model->validate();
     });
 }
Example #24
0
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->model = get_called_class();
     });
 }
Example #25
0
 /**
  * Boot the model.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::creating(function ($user) {
         $user->token = str_random(30);
     });
 }
Example #26
0
 /**
  * Override the boot method to bind model event listeners.
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     static::saved(function (Deployment $model) {
         event(new ModelChanged($model, 'deployment'));
     });
 }
Example #27
0
 protected static function boot()
 {
     parent::boot();
     static::deleting(function ($unit) {
         $unit->Tenants()->delete();
     });
 }
 protected static function boot()
 {
     parent::boot();
     static::deleting(function ($taskList) {
         $taskList->tasks()->delete();
     });
 }
Example #29
0
 public static function boot()
 {
     parent::boot();
     static::deleted(function ($showtime) {
         $showtime->timeslots()->delete();
     });
 }
Example #30
0
 public static function boot()
 {
     parent::boot();
     Tag::deleting(function ($tag) {
         $tag->stations()->detach();
     });
 }