Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
cursor メソッド
<?php
namespace App\Console\Commands;
use App\Post;
use Illuminate\Console\Command;
class FetchPost extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fetch:posts';
/**
* The console command description.
*
* @var string
*/
protected $description = 'fetch post';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// 死ぬ Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes)
$posts = Post::all();
// 死なない
$posts = Post::cursor();
foreach ($posts as $post) {
$this->info($post->body);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment