我刚刚将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 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"
},
}
您将不得不等待下一个标记的Laravel 8.x版本。目前,我们在8.9.0
其中也没有包括这种变化呢。
在将框架添加到8.x文档之前,这确实是管理该框架的人员的错误。
在标记并发布它之后,您必须更新对框架的依赖laravel/framework
,才能使用该方法。
composer update laravel/framework
或更新所有部门
composer update
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句