Illuminate\Database\Eloquent\Builder::firstOrFail PHP Method

firstOrFail() public method

Execute the query and get the first result or throw an exception.
public firstOrFail ( array $columns = ['*'] ) : Model | static
$columns array
return Model | static
    public function firstOrFail($columns = ['*'])
    {
        if (!is_null($model = $this->first($columns))) {
            return $model;
        }
        throw (new ModelNotFoundException())->setModel(get_class($this->model));
    }

Usage Example

Exemplo n.º 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;
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::firstOrFail