Skip to content

Commit

Permalink
use related model for methods
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 24, 2020
1 parent ac6587c commit d9720c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Eloquent/Relations/BelongsToMany.php
Expand Up @@ -585,7 +585,7 @@ public function findOrNew($id, $columns = ['*'])
*/
public function firstOrNew(array $attributes)
{
if (is_null($instance = $this->where($attributes)->first())) {
if (is_null($instance = $this->related->where($attributes)->first())) {
$instance = $this->related->newInstance($attributes);
}

Expand All @@ -602,7 +602,7 @@ public function firstOrNew(array $attributes)
*/
public function firstOrCreate(array $attributes, array $joining = [], $touch = true)
{
if (is_null($instance = $this->where($attributes)->first())) {
if (is_null($instance = $this->related->where($attributes)->first())) {
$instance = $this->create($attributes, $joining, $touch);
}

Expand All @@ -620,7 +620,7 @@ public function firstOrCreate(array $attributes, array $joining = [], $touch = t
*/
public function updateOrCreate(array $attributes, array $values = [], array $joining = [], $touch = true)
{
if (is_null($instance = $this->where($attributes)->first())) {
if (is_null($instance = $this->related->where($attributes)->first())) {
return $this->create($values, $joining, $touch);
}

Expand Down

0 comments on commit d9720c0

Please sign in to comment.