Total Complexity | 4 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait HasOneOrMany |
||
8 | { |
||
9 | /** |
||
10 | * Get the first related record matching the attributes or create it. |
||
11 | * |
||
12 | * @param array $attributes |
||
13 | * @param array $values |
||
14 | * @return \Illuminate\Database\Eloquent\Model |
||
15 | */ |
||
16 | 1 | public function firstOrCreate(array $attributes = [], array $values = []) |
|
17 | { |
||
18 | /** @phpstan-ignore-next-line */ |
||
19 | 1 | $instance = $this->where(associativeFlatten($attributes))->first(); |
|
|
|||
20 | 1 | if (is_null($instance)) { |
|
21 | 1 | $instance = $this->create(array_merge($attributes, $values)); |
|
22 | } |
||
23 | |||
24 | 1 | return $instance; |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * Get the first related model record matching the attributes or instantiate it. |
||
29 | * |
||
30 | * @param array $attributes |
||
31 | * @param array $values |
||
32 | * @return \Illuminate\Database\Eloquent\Model |
||
33 | */ |
||
34 | 1 | public function firstOrNew(array $attributes = [], array $values = []) |
|
45 | } |
||
46 | } |
||
47 |