当前位置: 首页>>代码示例>>PHP>>正文


PHP Eloquent::boot方法代码示例

本文整理汇总了PHP中Eloquent::boot方法的典型用法代码示例。如果您正苦于以下问题:PHP Eloquent::boot方法的具体用法?PHP Eloquent::boot怎么用?PHP Eloquent::boot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Eloquent的用法示例。


在下文中一共展示了Eloquent::boot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->{$model->getKeyName()} = (string) PaperworkHelpers::generateUuid('PaperworkModel');
     });
 }
开发者ID:Liongold,项目名称:paperwork,代码行数:7,代码来源:PaperworkModel.php

示例2: boot

 /**
  * Listen for save event
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function ($model) {
         return $model->validate();
     });
 }
开发者ID:leebivip,项目名称:laravel_cmp,代码行数:10,代码来源:Model.php

示例3: boot

 public static function boot()
 {
     parent::boot();
     static::created(function ($topic) {
         SiteStatus::newTopic();
     });
 }
开发者ID:6174,项目名称:phphub,代码行数:7,代码来源:Topic.php

示例4: boot

 /**
  * Nos registramos para los listener de laravel
  * si un hijo desea usar uno debe sobreescribir el metodo.
  * Docs: @link http://laravel.com/docs/eloquent#model-events
  */
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         return $model->creatingModel($model);
     });
     static::created(function ($model) {
         return $model->createdModel($model);
     });
     static::updating(function ($model) {
         return $model->updatingModel($model);
     });
     static::updated(function ($model) {
         return $model->updatedModel($model);
     });
     static::saving(function ($model) {
         return $model->savingModel($model);
     });
     static::saved(function ($model) {
         return $model->savedModel($model);
     });
     static::deleting(function ($model) {
         return $model->deletingModel($model);
     });
     static::deleted(function ($model) {
         return $model->deletedModel($model);
     });
 }
开发者ID:richarrieta,项目名称:miequipo,代码行数:33,代码来源:BaseModel.php

示例5: boot

 public static function boot()
 {
     parent::boot();
     static::creating(function ($parte) {
         $parte->user_created = Auth::user()->user;
     });
 }
开发者ID:kuell,项目名称:buriti,代码行数:7,代码来源:InvestigacaoParteCorpo.php

示例6: boot

 public static function boot()
 {
     parent::boot();
     static::deleted(function ($group) {
         Schedule::destroy($group->schedules()->lists('id'));
     });
 }
开发者ID:sharad23,项目名称:power,代码行数:7,代码来源:Group.php

示例7: boot

 public static function boot()
 {
     parent::boot();
     static::updating(function ($setor) {
         $setor->usuario_alteracao = Auth::user()->user;
     });
 }
开发者ID:kuell,项目名称:buriti,代码行数:7,代码来源:Setor.php

示例8: boot

 /**
  * The "booting" method of the model.
  *
  * @return void
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function (\Eloquent $model) {
         // If a new image file is uploaded, could be create or edit...
         $dirty = $model->getDirty();
         if (array_key_exists('filename', $dirty)) {
             // Set the width and height in the database
             list($width, $height) = getimagesize($model->getAbsolutePath('original'));
             $model->width = $width;
             $model->height = $height;
             // Now if editing only...
             if ($model->exists) {
                 $oldFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('filename');
                 $newFilename = $dirty['filename'];
                 // Delete the old files, rename the newly uploaded files to the same as the old files and set the
                 // filename field back to the old filename. This is all required because when uploading a new file
                 // it is given a different, random filename, but when we're editing an image, we want to replace the
                 // old with the new
                 $model->deleteFiles($oldFilename);
                 $model->renameFiles($newFilename, $oldFilename);
                 // Rename new files back to the same as the old files
                 $model->filename = $oldFilename;
             }
         }
     });
     static::deleted(function ($model) {
         $model->deleteFiles();
     });
 }
开发者ID:fbf,项目名称:laravel-images,代码行数:35,代码来源:Image.php

示例9: boot

 public static function boot()
 {
     parent::boot();
     static::deleted(function ($question) {
         Option::destroy($question->options()->lists('id'));
     });
 }
开发者ID:shankargiri,项目名称:Quantum-Vic-La-Trobe-L4,代码行数:7,代码来源:Question.php

示例10: boot

 public static function boot()
 {
     parent::boot();
     static::created(function ($record) {
         $kitTypeID = $record->KitType;
         $kitID = $record->ID;
         Logs::LogMsg(4, $kitTypeID, $kitID, null, "Created Kit: " . $record->Name);
         return true;
     });
     static::updating(function ($record) {
         $kitTypeID = $record->KitType;
         $kitID = $record->ID;
         $dirty = $record->getDirty();
         foreach ($dirty as $field => $newdata) {
             $olddata = $record->getOriginal($field);
             if ($olddata != $newdata) {
                 Logs::LogMsg(5, $kitTypeID, $kitID, null, "Changed Kit field: " . $field . " From:" . $olddata . " To:" . $newdata);
             }
         }
         return true;
     });
     static::deleting(function ($record) {
         $kitTypeID = $record->KitType;
         $kitID = $record->ID;
         Logs::LogMsg(6, $kitTypeID, $kitID, null, "Deleted Kit: " . $record->Name);
         return true;
     });
 }
开发者ID:KWinston,项目名称:EPLProject,代码行数:28,代码来源:Kits.php

示例11: boot

 public static function boot()
 {
     parent::boot();
     // Overriding the slug method to prefix with a forward slash
     self::$sluggable['method'] = function ($string, $sep) {
         return '/' . \Str::slug($string, $sep);
     };
     static::creating(function ($page) {
         // If the record is being created and there is a "main image" supplied, set it's width and height
         if (!empty($page->main_image)) {
             $page->updateMainImageSize();
         }
     });
     static::created(function ($page) {
         // If the record is being created and there is a "main image" supplied, set it's width and height
         if (!empty($page->main_image)) {
             $page->updateMainImageSize();
         }
     });
     static::updating(function ($page) {
         // If the record is about to be updated and there is a "main image" supplied, get the current main image
         // value so we can compare it to the new one
         $page->oldMainImage = self::where('id', '=', $page->id)->first()->pluck('main_image');
         return true;
     });
     static::updated(function ($page) {
         // If the main image has changed, and the save was successful, update the database with the new width and height
         if (isset($page->oldMainImage) && $page->oldMainImage != $page->main_image) {
             $page->updateMainImageSize();
         }
     });
 }
开发者ID:fbf,项目名称:laravel-pages,代码行数:32,代码来源:Page.php

示例12: boot

 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $data = array('district_id' => $model->district_id, 'name' => $model->name);
         $rules = array('district_id' => 'required|integer|min:1|max:300000', 'name' => 'required|min:3|max:50');
         $validator = Validator::make($data, $rules);
         if ($validator->fails()) {
             throw new ValidationException(null, null, null, $validator->messages());
         } else {
             return $model->validate();
         }
     });
     static::updating(function ($model) {
         $data = array('district_id' => $model->district_id, 'name' => $model->name);
         $rules = array('district_id' => 'required|integer|min:1|max:300000', 'name' => 'required|min:3|max:50');
         $validator = Validator::make($data, $rules);
         if ($validator->fails()) {
             throw new ValidationException(null, null, null, $validator->messages());
         } else {
             return true;
         }
     });
     static::deleting(function ($model) {
         $cities = City::where('municipality_id', '=', $model->id)->get();
         foreach ($cities as $city) {
             $city = City::find($city->id)->delete();
         }
         return true;
     });
 }
开发者ID:mertindervish,项目名称:registerbg,代码行数:31,代码来源:Municipality.php

示例13: boot

 public static function boot()
 {
     parent::boot();
     static::created(function ($record) {
         $kitTypeID = $record->kit->KitType;
         $kitID = $record->kit->ID;
         Logs::LogMsg(10, $kitTypeID, $kitID, $record->ID, "Added content: " . $record->Name);
         return true;
     });
     static::updating(function ($record) {
         $kitTypeID = $record->kit->KitType;
         $kitID = $record->kit->ID;
         $dirty = $record->getDirty();
         foreach ($dirty as $field => $newdata) {
             $olddata = $record->getOriginal($field);
             if ($olddata != $newdata) {
                 Logs::LogMsg(11, $kitTypeID, $kitID, $record->ID, "Changed " . $field . " From:" . $olddata . " To:" . $newdata);
             }
         }
         return true;
     });
     static::deleting(function ($record) {
         $kitTypeID = $record->kit->KitType;
         $kitID = $record->kit->ID;
         Logs::LogMsg(12, $kitTypeID, $kitID, $record->ID, "Removed Contents: " . $record->Name);
         return true;
     });
 }
开发者ID:KWinston,项目名称:EPLProject,代码行数:28,代码来源:KitContents.php

示例14: boot

 public static function boot()
 {
     parent::boot();
     static::saving(function ($module) {
         $module->plaintext = strip_tags($module->html);
     });
 }
开发者ID:Rotron,项目名称:angel,代码行数:7,代码来源:PageModule.php

示例15: boot

 public static function boot()
 {
     parent::boot();
     //validation on create
     static::creating(function ($customer) {
         return $customer->isValid();
     });
     //This event will delete all related model in category model
     static::deleted(function ($cs) {
         //Deletes all customerlog related to a customer
         $c = $cs->customerlog()->lists('id');
         if (!empty($c)) {
             Customerlog::destroy($c);
         }
         //Deletes all Receipt related to a customer
         $r = $cs->receipt()->lists('id');
         if (!empty($r)) {
             Receipt::destroy($r);
         }
         //Deletes all Salelog related to a customer
         $s = $cs->salelog()->lists('id');
         if (!empty($s)) {
             Salelog::destroy($s);
         }
     });
     //validation on update
     static::updating(function ($customer) {
         //return $customer->isValid();
     });
 }
开发者ID:sliekasirdis79,项目名称:POS,代码行数:30,代码来源:Customer.php


注:本文中的Eloquent::boot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。