/** * 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(); }); }
protected static function boot() { parent::boot(); static::creating(function ($model) { $model->{$model->getKeyName()} = (string) PaperworkHelpers::generateUuid('PaperworkModel'); }); }
public static function boot() { parent::boot(); static::created(function ($topic) { SiteStatus::newTopic(); }); }
/** * Listen for save event */ protected static function boot() { parent::boot(); static::saving(function ($model) { return $model->validate(); }); }
public static function boot() { parent::boot(); static::creating(function ($parte) { $parte->user_created = Auth::user()->user; }); }
/** * 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); }); }
public static function boot() { parent::boot(); static::updating(function ($setor) { $setor->usuario_alteracao = Auth::user()->user; }); }
public static function boot() { parent::boot(); static::deleted(function ($group) { Schedule::destroy($group->schedules()->lists('id')); }); }
public static function boot() { parent::boot(); static::deleted(function ($question) { Option::destroy($question->options()->lists('id')); }); }
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; }); }
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(); } }); }
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; }); }
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; }); }
public static function boot() { parent::boot(); static::saving(function ($module) { $module->plaintext = strip_tags($module->html); }); }
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(); }); }
public static function boot() { parent::boot(); static::deleting(function ($tag) { DB::statement('DELETE FROM book_tag WHERE tag_id = ?', array($tag->id)); }); }
public static function boot() { parent::boot(); static::updated(function ($cache) { Cache::flush(); }); }
public static function boot() { parent::boot(); static::saving(function ($model) { $model->beforeSave(); }); }
/** * Validates on save * * @return bool */ public static function boot() { parent::boot(); static::saving(function ($item) { return $item->validate(); }); }
public static function boot() { parent::boot(); static::saving(function ($post) { return $post->validate(); }); }
public static function boot() { parent::boot(); static::creating(function ($model) { $model->{$model->getKeyName()} = substr((string) $model->generateUuid(), 0, 36); }); }
/** * The "booting" method of the model. * * @return void */ protected static function boot() { parent::boot(); static::saving(function (\Eloquent $model) { // If a new download file is uploaded, could be create or edit... $dirty = $model->getDirty(); if (array_key_exists('filename', $dirty)) { $file = new \SplFileInfo($model->getAbsolutePath()); $model->filesize = $file->getSize(); $model->extension = strtoupper($file->getExtension()); // Now if editing only... if ($model->exists) { $oldFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('filename'); $newFilename = $dirty['filename']; // Delete the old file if the filename is different to the new one, and it therefore hasn't been replaced if ($oldFilename != $newFilename) { $model->deleteFile($oldFilename); } } } // If a download is edited and the image is changed... if (array_key_exists('image', $dirty) && $model->exists) { $oldImageFilename = self::where($model->getKeyName(), '=', $model->id)->first()->pluck('image'); $model->deleteImageFiles($oldImageFilename); } }); static::deleted(function ($model) { $model->deleteFile(); $model->deleteImageFiles(); }); }
public static function boot() { parent::boot(); // Setup event bindings... Balance::saving(function ($balance) { $balance->user_id = Auth::id(); return $balance; }); $user_id = Auth::id(); $balance = Balance::where('user_id', $user_id)->orderBy('id', 'DESC')->first(); if (count($balance) > 0) { $date = Carbon::createFromFormat('Y-m-d H:i:s', $balance->created_at); if ($date->isToday()) { // Deixa como está. } else { // Cria o pro=imeiro registro $todayAmount = DB::table('transactions')->where('created_at', '>', date("Y-m-d") . " 00:00:00")->where('created_at', '<=', date('Y-m-d H:i:s'))->where('user_id', Auth::id())->where('done', 1)->sum('amount'); $newAmount = $balance->amount + $todayAmount; // Cria um novo pro dia de hoje $balance = Balance::create(['amount' => $newAmount, 'user_id' => $user_id]); } } else { // Cria o pro=imeiro registro $amount = DB::table('transactions')->where('created_at', '<=', date('Y-m-d H:i:s'))->where('user_id', Auth::id())->where('done', 1)->sum('amount'); $balance = Balance::create(['amount' => $amount, 'user_id' => $user_id]); } }
public static function boot() { parent::boot(); // Assign input to the columns() static::saving(function ($model) { if ($model->skipEvents) { return; } $model->assign(); }); static::creating(function ($model) { if ($model->reorderable) { $model->order = $model->count(); } }); // Fill in the `order` gap after deleting a model. static::deleted(function ($model) { if (!$model->reorderable) { return; } $order = 0; foreach ($model->orderBy('order')->get() as $object) { $object->order = $order++; $object->save(); } }); }
public static function boot() { parent::boot(); static::deleting(function ($photo) { $photo->galleries()->detach($photo->id); return true; }); static::deleted(function ($photo) { unlink(public_path() . \Config::get('laravel-photogallery::upload_dir') . '/' . $photo->path); $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/"; $formats = \Config::get('laravel-photogallery::formats'); foreach ($formats as $name => $format) { unlink($destination . $name . '/' . $photo->path); } }); static::created(function ($photo) { $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/"; $orig = $destination . $photo->path; $img = \Image::make($orig); $formats = \Config::get('laravel-photogallery::formats'); foreach ($formats as $name => $format) { $img->resize($format['w'], $format['h'], function ($constraint) { $constraint->aspectRatio(); }); $img->save($destination . $name . '/' . $photo->path, $format['q']); } }); }
public static function boot() { parent::boot(); static::creating(function ($produto) { $produto->user_created = Auth::user()->user; $produto->user_updated = Auth::user()->user; $produto->situacao = 'requisitado'; }); static::updating(function ($produto) { if (Input::get('situacao') == 'comprado') { $produto->user_compra = Auth::user()->user; $produto->data_compra = date('Y-m-d'); } else { if (Input::get('situacao') == 'reprovado') { $produto->user_reprovacao = Auth::user()->user; $produto->data_reprovacao = date('Y-m-d'); } else { if (Input::get('situacao') == 'recebido') { $produto->user_recebimento = Auth::user()->user; $produto->data_recebimento = date('Y-m-d'); } else { if (Input::get('situacao') == 'devolvido') { $produto->user_devolucao = Auth::user()->user; $produto->data_devolucao = date('Y-m-d'); } } } } $produto->user_updated = Auth::user()->user; }); }
public static function boot() { parent::boot(); if (!static::$logActivities) { return true; } // Attach to created event static::created(function ($model) { Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Created', 'description' => 'Created ' . get_class($model)]); }); static::deleted(function ($model) { Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Deleted', 'description' => 'Deleted ' . get_class($model)]); }); static::updating(function ($model) { $details = ''; // Get changes in model foreach ($model->getDirty() as $attribute => $value) { $original = $model->getOriginal($attribute); $details .= "{$attribute}: from '{$original}' to '{$value}'\r\n"; } // Do not log if there's no changes if (!empty($details)) { Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Updated', 'description' => 'Updated ' . get_class($model), 'details' => trim($details)]); } }); }
public static function boot() { parent::boot(); static::deleted(function ($agent) { ${$agent}->quotations()->delete(); }); }
public static function boot() { parent::boot(); static::deleted(function ($user) { SocialProfile::destroy($user->socialProfiles->lists('id')); }); }
public static function boot() { parent::boot(); static::creating(function ($natureza) { $natureza->user_created = Auth::user()->user; }); }