Get the first record matching the attributes or create it.
public firstOrCreate ( array $attributes, array $values = [] ) : |
||
$attributes | array | |
$values | array | |
return |
/** * Find an item by given values, or create it if it doesn't exist * * @param array $data * @return \Illuminate\Database\Eloquent\Model */ public function firstOrCreate(array $data) { $item = $this->builder->firstOrCreate($data); // Reset the query builder $this->newBuilder(); return $item; }
/** * Get the first record matching the attributes or create it. * * @param array $attributes * @return \Illuminate\Database\Eloquent\Model * @static */ public static function firstOrCreate($attributes) { return \Illuminate\Database\Eloquent\Builder::firstOrCreate($attributes); }