【发布时间】:2016-09-25 09:34:49
【问题描述】:
在使用 Eloquent ORM 进行 JOIN 后尝试对某些结果进行分页时,我遇到了一种奇怪的行为(我猜是我的错)。
这是导致 Laravel 返回空白(未显示错误)500 错误页面的代码:
return Entry::join('articles', 'entries.id', '=', 'articles.entryID')
->orderBy('articles.created_at', 'desc')
->paginate(15, array('articles.*'));
如果我将paginate(...) 与get(...) 交换,页面将正确显示并返回数据。
编辑:
这就是我创建articles 和entries 表的方式:
// Entries
Schema::create('entries', function($table) {
$table->string('app', 20);
$table->bigInteger('comments');
$table->bigIncrements('id');
$table->string('owner', 255)
->foreign('owner')
->references('username')
->on('users');
$table->dateTime('timestamp');
$table->bigInteger('views');
$table->bigInteger('votes');
$table->dateTime('created_at');
$table->dateTime('deleted_at');
$table->dateTime('updated_at');
});
// Articles
Schema::create('articles', function($table) {
$table->bigIncrements('id');
$table->string('author')
->foreign('author')
->references('username')
->on('users');
$table->text('content');
$table->bigInteger('entryID')
->foreign('entryID')
->references('id')
->on('entries');
$table->string('status', 20);
$table->string('summary', 1000);
$table->string('title', 255);
$table->dateTime('created_at');
$table->dateTime('deleted_at');
$table->dateTime('updated_at');
});
编辑 2:
这是我在laravel.log得到的:
[2014-08-26 19:59:54] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 129499136 bytes)' in /usr/share/nginx/html/webname/vendor/laravel/framework/src/Illuminate/Support/helpers.php:605
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []
编辑 3:
我已经禁用了内存限制和日志
DB::connection()->disableQueryLog();
ini_set('memory_limit', '-1');
但整个系统会冻结大约 1 分钟,就像它开始循环一样。
编辑 4:
我也在这里添加了我的问题:http://help.laravel.io/00f4a0793d2291d73214e0b6f56320b84caaf51d
编辑 5:
我的系统似乎有问题,或者是 Laravel 中的错误。
我也尝试过手动创建分页器:
$entries = Entry::join('articles', 'entries.id', '=', 'articles.entryID')
->orderBy('entries.created_at', 'desc')
->get(); // Data is correctly retrieved from the DB
$paginator = Paginator::make($entries->toArray(), self::count());
dd($paginator);
die();
页面仍未呈现,我不断收到错误:Allowed memory size of 134217728 bytes exhausted
【问题讨论】:
-
你是怎么解决这个问题的?
标签: laravel pagination