我正在运行Laravel 5.8,在 seeder 时出现此错误

Seeding: CategoriesTableSeeder

ErrorException : implode(): Passing glue string after array is deprecated. Swap the parameters

在/Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Provider/Lorem.php:95

91|
92|         $words = static::words($nbWords);
93|         $words[0] = ucwords($words[0]);
94|
95|         return implode($words, ' ') . '.';
96|     }
97|
98|     /**
99|      * Generate an array of sentences
  Exception trace:

  1   implode(" ")
      /Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Provider/Lorem.php:95

  2   Faker\Provider\Lorem::sentence()
      /Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Generator.php:222

>  Please use the argument -v to see more details.

该应用程序在使用PHP7.3和7.2的CI中通过了测试,所以问题可能是我本地机器"OSX"中的PHP7.4

这是我的种子文件

<?php

use Saly\Category;
use Illuminate\Database\Seeder;

class CategoriesTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        factory(Category::class, 3)->create();
    }
}

And the factory

<?php

use Saly\Category;
use Faker\Generator as Faker;

$factory->define(Category::class, function (Faker $faker) {
    $name = $faker->sentence(4, true); // Here maybe?
    return [
        'name' => $name,
        'slug' => sluggify($name),
    ];
});

I think the problem is in the line where sentence() is used but I can't tell how to solve it because I just copied that line from the Faker docs

What does this error mean and how can I solve it?

推荐答案

这已经在Faker的最新版本中修复.在你的错误中,它说

> 95| return implode($words, ' ') . '.';

but if we look at line 95 of the source we see:

> 95| return implode(' ', $words) . '.';

所以,你所需要做的就是获取最新版本的Faker,可能是通过

composer update fzaninotto/faker

Laravel相关问答推荐

为什么使用 created_at 表在迁移错误中创建表?

如何从laravel中的另一个表中获取用户名

验证错误后的 Laravel 自定义重定向

Laravel 5 如何配置 Queue 数据库驱动程序以连接到非默认数据库?

Laravel/Eloquent:致命错误:在非对象上调用成员函数 connection()

Laravel 如何处理来自浏览器的 PUT 请求?

Laravel Blade:@stop VS @show VS @endsection VS @append

Laravel 中的 index()" 是什么意思?

Laravel 5在blade中 echo 包含html的会话变量

laravel 5 - assets资源 list 中未定义 css 文件?

何时在 Laravel 中使用 Repository vs Service vs Trait?

如何在 Laravel Eloquent 中 Select 某些字段?

Laravel 5.2 身份验证不起作用

Laravel / Eloquent内存泄漏重复检索相同的记录

在 vue.js 中使用 Laravel 的Gate/Authorization

Laravel 获取文件内容

Laravel 4 - 一个表单中有两个提交按钮,并且两个提交都由不同的操作处理

在 Laravel 中判断会话超时

如何访问 Laravel 集合中的第 n 个项目?

Laravel or where