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 202cc98 commit d8ad231
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 @@ -257,11 +257,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 d8ad231

Please sign in to comment.