Execute the query and get the first result or throw an exception.
public firstOrFail ( array $columns = ['*'] ) : |
||
$columns | array | |
return |
/** * Get the first specified model record from the database * * @return \Illuminate\Database\Eloquent\Model */ public function first() { $this->newQuery()->eagerLoad()->setClauses()->setScopes(); $model = $this->query->firstOrFail(); $this->unsetClauses(); return $model; }
/** * @param $value * @param array $in * @return Model */ public function searchFor($value, array $in) { foreach ($in as $key) { $this->model = $this->model->orWhere($key, $value); } return $this->model->firstOrFail(); }
/** * @param $id * @param $data * @param bool $orFail * @return mixed * * updates an existing record */ public function update($id, $data, $orFail = false) { if ($id instanceof Model) { $this->model = $id; } else { $this->model = new $this->modelClass(); $table = $this->model->getTable(); $this->model = $this->model->newQuery(); $this->model->where($table . '.' . $this->identifier, '=', $id); $this->model = $orFail ? $this->model->firstOrFail() : $this->model->first(); if (!$this->model) { return false; } } if (!is_array($data)) { $data = $this->extractData($data); } $this->model->fill($data); foreach ($this->updateDefaults() as $key => $value) { $this->model->{$key} = $value; } $this->model->save(); return $this->model; }
/** * Execute the query and get the first result or throw an exception. * * @param array $columns * @return \Illuminate\Database\Eloquent\Model|static * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * @static */ public static function firstOrFail($columns = array()) { return \Illuminate\Database\Eloquent\Builder::firstOrFail($columns); }
/** * @param array $columns * @return mixed */ public function first() { $this->applyCriteria(); return $this->execute($this->model->firstOrFail()); }