Reputation: 720
I just upgraded laravel to v8, I am trying to run the upsert function documented here on a seeder.
Here is a code sample of what I am running
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class NewspaperSeeder extends Seeder
{
/**
* Run the database seeders.
*
* @return void
*/
public function run()
{
DB::table("newspapers")->upsert(
["rows to insert"],
["primary key"],
["attributes to update if duplicate"]);
}
}
Meanwhile, I end up getting this error when I run php artisan db:seed
BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::upsert()
at vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50
46▕ * @throws \BadMethodCallException
47▕ */
48▕ protected static function throwBadMethodCallException($method)
49▕ {
➜ 50▕ throw new BadMethodCallException(sprintf(
51▕ 'Call to undefined method %s::%s()', static::class, $method
52▕ ));
53▕ }
54▕ }
• Bad Method Call: Did you mean Illuminate\Database\Query\Builder::insert() ?
I followed Upgrading Guide on the official documentation, run composer update
{
"require": {
"php": "^7.2.5",
"ext-json": "^7.4",
"doctrine/dbal": "^2.10",
"fideloper/proxy": "^4.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^6.3",
"laravel/framework": "^8.0",
"laravel/legacy-factories": "^1.0",
"laravel/passport": "^10.0",
"laravel/socialite": "^5.0",
"laravel/tinker": "^2.0",
"laravel/ui": "^3.0"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"facade/ignition": "^2.3.6",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.0"
},
}
Upvotes: 2
Views: 7008
Reputation: 50491
You will have to wait for the next tagged release of Laravel 8.x. Currently we are on 8.9.0
which does not include this change yet.
This is an error on the part of the people managing the framework for adding this to the 8.x docs before it is actually in a release for 8.x.
After it is tagged and released you will have to update your dependency on the framework, laravel/framework
, to use that method.
composer update laravel/framework
Or update all deps
composer update
Upvotes: 2