當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。