测试demo如下
<?php
use Illuminate\Database\Seeder;
class MohuaniSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->collectContinue();
$this->command->info("--------------");
$this->collectBreak();
}
public function collectContinue () {
$arrList = [
"a" => "A",
"b" => "B",
"c" => "C",
];
$this->command->info(111);
collect($arrList)->each(function ($arr) {
$this->command->info(222);
if ($arr == "b") {
$this->command->info(333);
return; // 跳出本次循环,类似continue
}
});
$this->command->info(444);
}
public function collectBreak () {
$arrList = [
"a" => "A",
"b" => "B",
"c" => "C",
];
$this->command->info(111);
collect($arrList)->each(function ($arr) {
$this->command->info(222);
if ($arr == "b") {
$this->command->info(333);
return false; // 跳出所有循环,类似break
}
});
$this->command->info(444);
}
}
运行seeder
php artisan db:seed --class=MohuaniSeeder
结果:
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 模板不会安装或需要功能定制以及二次开发?
发表评论
还没有评论,快来抢沙发吧!