本文整理匯總了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();
}
}
});
}