0
votes

For some reason, I am getting a BadMethodCallException when using the withDefault() method. That's what I have in my Model:

public function user()
{
    return $this->belongsTo('App\User')->withDefault([
        'name' => 'Guest Author',
    ]);
}

I got:

BadMethodCallException in Builder.php line 2451: Call to undefined method Illuminate\Database\Query\Builder::withDefault() in Builder.php line 2451

1

1 Answers

2
votes

After an hour of searching, I found that it was because I was currently using an older laravel version which did not have the withDefault method available. I have upgraded it from 5.4.23 to 5.4.32 (latest) by simply running composer update.

You can check your current laravel version by running php artisan --version

For the more curious, the withDefault method was introduced in Laravel version 5.4.28 through these PRs: #19733, #19788, 1137d86