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() ?
Edit (composer.json):
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"
},
}