laravel ErrorException : implode(): 在数组被弃用后传递胶水字符串。交换参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/59541888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ErrorException : implode(): Passing glue string after array is deprecated. Swap the parameters
提问by Salim Djerbouh
Am running Laravel 5.8 and getting this error when seeding
我正在运行 Laravel 5.8 并在播种时出现此错误
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
ErrorException : implode(): 在数组被弃用后传递胶水字符串。交换参数
在 /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.
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"
该应用程序使用 PHP 7.3 和 7.2 在 CI 中通过测试就好了,所以问题可能是我本地机器“OSX”中的 PHP 7.4
Here's my seed file
这是我的种子文件
<?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
我认为问题出在使用的行中,sentence()
但我不知道如何解决它,因为我只是从 Faker 文档中复制了该行
What does this error mean and how can I solve it?
这个错误是什么意思,我该如何解决?
Thanks in advance
提前致谢
回答by dave
This has already been fixed in the most recent version of Faker. In your error it says
这已经在最新版本的 Faker 中得到修复。在你的错误中它说
> 95| return implode($words, ' ') . '.';
but if we look at line 95 of the sourcewe see:
但是如果我们查看源代码的第 95 行,我们会看到:
> 95| return implode(' ', $words) . '.';
So, all you need to do is pull the latest version of Faker, probably by doing
所以,你需要做的就是拉取最新版本的 Faker,可能是这样做
composer update fzaninotto/faker
回答by AWS PS
You can swap (in affect lines with implode
command) glue and array.
您可以交换(在implode
命令的影响行中)胶水和数组。
Example:
例子:
return implode($words,' ') . '.';
to
到
return implode(' ',$words) . '.';
also, The newest version of the fzaninotto/faker
package solves this issue.
此外,最新版本的fzaninotto/faker
软件包解决了这个问题。
回答by Ariful Islam
This is happend for backward version of fzaninotto/faker. Update your faker using below command
这发生在fzaninotto/faker 的落后版本中。使用以下命令更新您的伪造者
composer update fzaninotto/faker