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

firstOrNew() public method

Get the first record matching the attributes or instantiate it.
public firstOrNew ( array $attributes, array $values = [] ) : Model
$attributes array
$values array
return Model
    public function firstOrNew(array $attributes, array $values = [])
    {
        if (!is_null($instance = $this->where($attributes)->first())) {
            return $instance;
        }
        return $this->model->newInstance($attributes + $values)->setConnection($this->query->getConnection()->getName());
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Get the first record matching the attributes or instantiate it.
  *
  * @param array $attributes
  * @return \Illuminate\Database\Eloquent\Model 
  * @static 
  */
 public static function firstOrNew($attributes)
 {
     return \Illuminate\Database\Eloquent\Builder::firstOrNew($attributes);
 }
All Usage Examples Of Illuminate\Database\Eloquent\Builder::firstOrNew