Skip to content

Commit

Permalink
Invert the firstOrNew if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Sep 26, 2023
1 parent 66d1109 commit 8a2ca69
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ protected function buildDictionary(Collection $results)
*/
public function firstOrNew(array $attributes = [], array $values = [])
{
if (is_null($instance = $this->where($attributes)->first())) {
$instance = $this->related->newInstance(array_merge($attributes, $values));
if (! is_null($instance = $this->where($attributes)->first())) {
return $instance;
}

return $instance;
return $this->related->newInstance(array_merge($attributes, $values));
}

/**
Expand Down

0 comments on commit 8a2ca69

Please sign in to comment.