在创建Paginator实例时将原始选择语句传递给laravel Eloquent

时间:2016-07-27 14:50:50

标签: php laravel-5 pagination laravel-query-builder

Laravel中的分页非常容易。我只是去:

$posts = Post::where( .... );
$posts->paginate(20, ['ID', 'title', 'body'], ....);

我正在尝试用ID, title, LEFT(body, 200)替换ID,标题,正文数组但是Laravel不接受这个!我发现我应该使用它来代替:

connection()->raw('ID, title, LEFT(body, 200) AS body');

为此,但paginate方法只接受一个数组。有办法吗?

1 个答案:

答案 0 :(得分:1)

这样做:

LOGGER_OBJECT.info("\r\n"); //New Line
LOGGER_OBJECT.info("Log Type\t: INFO"); //Log Type
LOGGER_OBJECT.info("\r\n");
LOGGER_OBJECT.info("Date & Time\t: "+SIMPLE_DATE_FORMAT_PATTERN.format(new Date()));//Current Date & Time
LOGGER_OBJECT.info("\r\n");