public static function boot() { parent::boot(); static::created(function ($topic) { SiteStatus::newUser(); }); }
/** * Set layout title and load resource view. * * @param string $view * @param array $labels * * @return Response */ protected function loadView($view, array $labels = null) { // Add data to the view $view = view('resource.' . $view)->with(['resource' => $this->resource, 'labels' => $labels ? (object) $labels : (object) $this->resource->getLabels()]); // Add data to the layout $this->layout->title = $this->resource->singular(); // Return layout + view return $this->layout($view); }
public static function createFromInput(\Controllers\Request $input, $id = null, $save = true) { $user = parent::createFromInput($input, $id, false); if ($input->has('password') && '' != $input->get('password')) { $user->password = bcrypt($input->get('password')); } if ($save) { $user->save(); } return $user; }
/** * Attach a listener to the 'deleted' event. */ public static function boot() { parent::boot(); // Adjust the order of the other roles on delete static::deleted(function ($role) { $adjust_roles = static::where('order', '>', $role->order)->get(); foreach ($adjust_roles as $r) { $r->order--; $r->save(); } }); }
public function fillByPost($post) { $e = new MultiException(); parent::fillByPost($post); $this->title = trim($this->title); $this->text = trim($this->text); if ('' === $this->title) { $e['title'] = new \Exception('Заголовок некорректен'); } if ('' === $this->text) { $e['text'] = new \Exception('Текст некорректен'); } if (count($e) > 0) { throw $e; } }
public static function boot() { // NOTE saving -> creating -> created -> saved // NOTE saving -> updating -> updated -> saved // NOTE deleting -> deleted -> restoring -> restored parent::boot(); // Validate the model static::saved(function ($doc) { Profile::purgeDocumentsCache(); }); static::deleted(function ($doc) { Profile::purgeDocumentsCache(); }); static::restored(function ($doc) { Profile::purgeDocumentsCache(); }); }
public static function boot() { // NOTE saving -> creating -> created -> saved // NOTE saving -> updating -> updated -> saved // NOTE deleting -> deleted -> restoring -> restored parent::boot(); // Validate the model static::saved(function ($profile) { // Purge permissions cache Cache::forget("profile{$profile->id}permissions"); }); static::deleted(function ($profile) { // Purge permissions and documents cache Cache::forget("profile{$profile->id}permissions"); Cache::forget("profile{$profile->id}documents"); }); }
public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setRules(['code' => [_('Code'), 'required|size:3|regex:/^[A-Z]+$/|unique'], 'name' => [_('Name'), 'required|max:64'], 'name2' => [_('Alt. name'), 'nullable|max:64'], 'symbol' => [_('Symbol'), 'nullable|max:8'], 'symbol2' => [_('Alt. symbol'), 'nullable|max:8'], 'symbol_position' => [_('Symbol position'), 'required|integer'], 'decimal_separator' => [_('Decimal separator'), 'required|size:1'], 'thousands_separator' => [_('Thousands separator'), 'nullable|size:1'], 'subunit' => [_('Subunit'), 'nullable|max:16'], 'subunit2' => [_('Alt. subunit'), 'nullable|max:16'], 'unicode_decimal' => [_('Unicode decimal'), 'nullable|max:32'], 'unicode_hexadecimal' => [_('Unicode hexadecimal'), 'nullable|max:16']]); }
public function __construct(array $attributes = array()) { parent::__construct($attributes); $this->setRules(array('name' => [_('Name'), 'required|alpha_space|max:64|unique'], 'full_name' => [_('Full name'), 'nullable|max:128|unique'], 'iso_3166_2' => [_('2 letters code'), 'required|size:2|regex:/^[A-Z]+$/|unique'], 'iso_3166_3' => [_('3 letters code'), 'required|size:3|regex:/^[A-Z]+$/|unique'], 'code' => [_('Numeric code'), 'required|size:3|regex:/^[0-9]+$/|unique'], 'capital' => [_('Capital'), 'nullable|max:64'], 'citizenship' => [_('Citizenship'), 'nullable|max:64'], 'region' => [_('Region code'), 'nullable|size:3|regex:/^[0-9]+$/'], 'subregion' => [_('Subregion code'), 'nullable|size:3|regex:/^[0-9]+$/'], 'eea' => [_('European Economic Area'), 'required|integer|min:0|max:1'], 'currency_id' => [_('Currency'), 'nullable|exists:currencies,id'])); }
/** * Check if given model is equal to this model. * * @param Model $model * @return bool */ public function is($model) { return $this->getKey() == $model->getKey(); }
/** * Sort model by parameters given in the URL * i.e: ?sortby=name&sortdir=desc * * @param \Illuminate\Database\Eloquent\Builder * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOrderByUrl($query) { $column = Input::get('sortby'); switch ($column) { default: return parent::scopeOrderByUrl($query); case 'user_id': $table = 'users'; $relatedColumn = 'username'; break; case 'provider_id': $table = 'authproviders'; $relatedColumn = 'title'; break; } $direction = Input::get('sortdir') === 'desc' ? 'desc' : 'asc'; return $query->select($this->getTable() . '.*')->leftJoin($table, $column, '=', "{$table}.id")->orderBy("{$table}.{$relatedColumn}", $direction); // Sort by related column }
/** * Override the default ::create method to automatically assign some attributes. * This also automatically sets up the role and sends the new user an email. * @param array $attributes * @param bool $sendEmail * @return static */ public static function create(array $attributes = [], $sendEmail = true) { // Set up the default parameters if (!isset($attributes['email']) && isset($attributes['username'])) { $attributes['email'] = $attributes['username'] . '@bath.ac.uk'; } if (!isset($attributes['password'])) { $password = str_random(15); $attributes['password'] = bcrypt($password); } if (!isset($attributes['status'])) { $attributes['status'] = true; } if (isset($attributes['type'])) { $type = $attributes['type']; unset($attributes['type']); } // Create the user $user = parent::create($attributes); if (isset($type)) { $user->type = $type; } if ($user && $sendEmail && isset($password)) { // Send an email to the new user Mail::queue('emails.users.create', ['name' => $user->forename, 'password' => $password], function ($message) use($user) { $message->subject('Your new Backstage account')->to($user->email, $user->name); }); } return $user; }
public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setRules(['name' => [_('Name'), 'required|max:64'], 'description' => [_('Description'), 'nullable|max:255'], 'type_id' => [_('Type'), 'required|exists:permissiontypes,id']]); }
/** * Sort model by parameters given in the URL * i.e: ?sortby=name&sortdir=desc * * @param \Illuminate\Database\Eloquent\Builder * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOrderByUrl($query) { $column = Input::get('sortby'); $direction = Input::get('sortdir') === 'desc' ? 'desc' : 'asc'; if ($column === 'name') { return $query->orderBy('title', $direction); } return parent::scopeOrderByUrl($query); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $data = Model::findOrFail($id); $data->delete(); return redirect()->route('routename')->with('status', 'Successfully Deleted'); }
public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setRules(['name' => [_('Name'), 'required|max:64|unique'], 'description' => [_('Description'), 'nullable|max:255']]); }
function __construct() { parent::__construct(); }
public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setRules(['name' => [_('Internal name'), 'required|min:3|max:32|alpha_dash|unique'], 'label' => [_('Label'), 'required|max:64|unique'], 'description' => [_('Description'), 'nullable|max:128'], 'value' => [_('Value'), 'required|max:64'], 'assignable' => [_('Assignable'), 'required|max:1|min:0'], 'rules' => [_('Validation rules'), 'required|max:255']]); }