firstOrFail() public méthode

Execute the query and get the first result or throw an exception.
public firstOrFail ( array $columns = ['*'] ) : Model | static
$columns array
Résultat Model | static
Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * @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();
 }
Exemple #3
0
 /**
  * @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;
 }
Exemple #4
0
 /**
  * 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);
 }
Exemple #5
0
 /**
  * @param array $columns
  * @return mixed
  */
 public function first()
 {
     $this->applyCriteria();
     return $this->execute($this->model->firstOrFail());
 }