本文整理汇总了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');
});
}
示例2: boot
/**
* Listen for save event
*/
protected static function boot()
{
parent::boot();
static::saving(function ($model) {
return $model->validate();
});
}
示例3: boot
public static function boot()
{
parent::boot();
static::created(function ($topic) {
SiteStatus::newTopic();
});
}
示例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);
});
}
示例5: boot
public static function boot()
{
parent::boot();
static::creating(function ($parte) {
$parte->user_created = Auth::user()->user;
});
}
示例6: boot
public static function boot()
{
parent::boot();
static::deleted(function ($group) {
Schedule::destroy($group->schedules()->lists('id'));
});
}
示例7: boot
public static function boot()
{
parent::boot();
static::updating(function ($setor) {
$setor->usuario_alteracao = Auth::user()->user;
});
}
示例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();
});
}
示例9: boot
public static function boot()
{
parent::boot();
static::deleted(function ($question) {
Option::destroy($question->options()->lists('id'));
});
}
示例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;
});
}
示例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();
}
});
}
示例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;
});
}
示例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;
});
}
示例14: boot
public static function boot()
{
parent::boot();
static::saving(function ($module) {
$module->plaintext = strip_tags($module->html);
});
}
示例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();
});
}