0

Laravel 中的分页非常简单。我只是去:

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

我正在尝试将 ID、title、body 数组替换为:ID, title, LEFT(body, 200)但 Laravel 不接受!我发现我应该改用这个:

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

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

4

1 回答 1

1

做这个:

$posts = Post::where( .... );
$posts->paginate(20, ['ID', 'title', \DB::raw('LEFT(body, 200) AS body')], ....);
于 2016-07-27T14:59:25.383 回答