public firstOrNew ( array $attributes, array $values = [] ) : |
||
$attributes | array | |
$values | array | |
return |
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());
}
/** * 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); }