mercredi 27 juillet 2016

Pass raw selection statement to laravel Eloquent while creating a Paginator instance

Pagination in Laravel is super easy. I simply go:

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

I am trying to replace the ID,title,body array with: ID, title, LEFT(body, 200) But Laravel doesn't accept that! I found out that I should use this instead:

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

For this to work, but the paginate method only accepts an array. Is there a way around it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire