Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

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

Am running Laravel 5.8 and getting this error when seeding

Seeding: CategoriesTableSeeder

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

at /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   FakerProviderLorem::sentence()
      /Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Generator.php:222

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

The app is passing tests just fine in CI using PHP 7.3 and 7.2 so the problem might be PHP 7.4 in my local machine "OSX"

Here's my seed file

<?php

use SalyCategory;
use IlluminateDatabaseSeeder;

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

And the factory

<?php

use SalyCategory;
use FakerGenerator 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This has already been fixed in the most recent version of Faker. In your error it says

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

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

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

So, all you need to do is pull the latest version of Faker, probably by doing

composer update fzaninotto/faker

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...