0

I am working on a project in laravel. I have sql queries as string in db. The queries are very important. There is no way to write them in laravel relationships because of some situation so

DB::select($table->query) I wanna paginate this with laravel paginate.

Ozal Zarbaliyev
  • 566
  • 6
  • 22

1 Answers1

1

Laravel Query Builder also implements the paginate() method:

DB::table($table->query)->paginate(15);

Check the documentation on this subject for further information.

Asur
  • 3,727
  • 1
  • 26
  • 34
  • Asur your solution not works. I found a way to do this. I get all ids from query, then make array of this ids, then Table::whereIn('id', $array)->paginate(15) this works. Thanks – Ozal Zarbaliyev Mar 28 '18 at 11:11
  • @OzalZarbaliyev I'm sorry but your question then was not clear enough, I can't find anything related to `whereIn` in your post, you asked just for a pagination method using the Laravel Query builder. – Asur Mar 28 '18 at 11:13
  • @OzalZarbaliyev It doesn't really matter but in the future try to be more specific in your questions :) – Asur Mar 28 '18 at 11:18
  • i did know ->paginate(15), before i asked question I tried paginate it it simple and first step :) That's why I said custom query from db which can be any query. – Ozal Zarbaliyev Mar 28 '18 at 12:58
  • @OzalZarbaliyev What I mean is that your question has no information at all apart from the pagination part – Asur Mar 28 '18 at 12:59
  • paginate not works with custom queries. gives Call to a member function paginate() on array. – Ozal Zarbaliyev Mar 28 '18 at 13:11
  • @OzalZarbaliyev https://laravel.com/docs/5.6/pagination#paginating-query-builder-results – Asur Mar 28 '18 at 13:14