我刚刚将laravel升级到v8,我试图在一个播种机上运行这里文档中的upsert函数。
下面是我正在运行的代码示例
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"]);
}
}同时,当我运行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() ?编辑(composer.json):
我遵循了官方文档升级指南,运行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"
},
}发布于 2020-10-08 21:43:07
您将不得不等待下一个标记发布的Laravel8.x。目前,我们使用的是8.9.0,它做的是,而不是,还没有包含此更改。
这是管理框架的人员在8.x发布之前将其添加到8.x文档的一个错误。
在对其进行标记和发布之后,您必须更新对框架laravel/framework的依赖关系,才能使用该方法。
composer update laravel/framework或更新所有deps
composer updatehttps://stackoverflow.com/questions/64270976
复制相似问题