本文整理汇总了PHP中app\Board::chunk方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::chunk方法的具体用法?PHP Board::chunk怎么用?PHP Board::chunk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Board
的用法示例。
在下文中一共展示了Board::chunk方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('board_adventures', function (Blueprint $table) {
$table->increments('adventure_id');
$table->binary('adventurer_ip');
$table->string('board_uri', 32);
$table->integer('post_id')->unsigned()->nullable()->default(NULL);
$table->timestamps();
$table->timestamp('expires_at');
$table->timestamp('expended_at')->nullable()->default(NULL);
$table->foreign('board_uri')->references('board_uri')->on('boards')->onDelete('cascade')->onUpdate('cascade');
});
Schema::table('posts', function (Blueprint $table) {
$table->integer('adventure_id')->unsigned()->nullable()->default(NULL)->after('locked_at');
$table->foreign('adventure_id')->references('adventure_id')->on('board_adventures')->onDelete('set null')->onUpdate('cascade');
});
Schema::table('boards', function (Blueprint $table) {
$table->timestamp('last_post_at')->nullable()->default(NULL)->after('updated_at');
});
Board::chunk(100, function ($boards) {
foreach ($boards as $board) {
$lastPost = $board->posts()->orderBy('created_at', 'desc')->limit(1)->get()->last();
if ($lastPost) {
$board->last_post_at = $lastPost->created_at;
$board->save();
}
}
});
}
示例2: runBoards
public function runBoards()
{
$this->command->comment("\tInserting board owner roles.");
$boardRole = $this->slugs()[Role::ID_OWNER];
Board::chunk(50, function ($boards) {
foreach ($boards as $board) {
$boardRole = $board->getOwnerRole();
if (!$boardRole) {
$boardRole = Role::getOwnerRoleForBoard($board);
$this->command->line("\t/{$board->board_uri}/ has no owner role.");
}
$roleModel = Role::firstOrCreate(['role' => $boardRole['role'], 'board_uri' => $board->board_uri, 'caste' => $boardRole['caste']]);
if ($roleModel->wasRecentlyCreated) {
$roleModel->fill(['name' => $boardRole['name'], 'capcode' => $boardRole['capcode'], 'inherit_id' => Role::ID_OWNER, 'system' => false, 'weight' => $boardRole['weight'] + 5])->save();
}
}
});
}