laravel 8 调用未定义的方法 upsert

laravel 8 call to undefined method upsert

我刚刚将 laravel 升级到 v8,我正在尝试 运行 在播种机上 here 记录的更新插入功能。

这是我的代码示例 运行ning

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"
    },
}

您将不得不等待 Laravel 8.x 的下一个标记版本。目前我们在 8.9.0 不包含此更改。

这是管理框架的人员在 8.x 实际发布之前将其添加到 8.x 文档中的错误。

标记并发布后,您必须更新对框架的依赖,laravel/framework,才能使用该方法。

 composer update laravel/framework

或更新所有部门

composer update