在创建分页器实例时将原始选择语句传递给 laravel Eloquent
Pass raw selection statement to laravel Eloquent while creating a Paginator instance
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');
为此,分页方法只接受一个数组。有解决办法吗?
这样做:
$posts = Post::where( .... );
$posts->paginate(20, ['ID', 'title', \DB::raw('LEFT(body, 200) AS body')], ....);
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');
为此,分页方法只接受一个数组。有解决办法吗?
这样做:
$posts = Post::where( .... );
$posts->paginate(20, ['ID', 'title', \DB::raw('LEFT(body, 200) AS body')], ....);