Вызов функции-члена paginate () для массива Laravel - PullRequest
0 голосов
/ 26 марта 2020

Я использую необработанный запрос, как показано ниже в BookController, и делаю paginate (5), как показано ниже. Но выдает эту ошибку "Call to a member function paginate() on array". Любое решение, пожалуйста.

 public function index()
        {
            try {
                $Book = DB::select('select b.id as id ,b.name as bk,c.name as Catagory,(select name from author_translators WHERE id = b.author_id) as Author,(select name from author_translators WHERE id = b.translate_id)as Translator,l.name as Language,pb.name as Publisher,b.publishing_date,b.edition,b.valume_number,b.ISBN from books b join categories c on b.category_id = c.id join publishers pb on b.publisher_id = pb.id join languages l on b.language_id = l.id')
               ->paginate(5);             
                return response()->json($Book);
            } catch (Exception $e) {
                return response()->json($e->getMessage(), 500);
            }
        }

Ответы [ 2 ]

1 голос
/ 26 марта 2020

Вы пропали без вести DB::table('books')

DB::table('books')->select('select b.id as id ,b.name as bk,c.name as Catagory,(select name from author_translators WHERE id = b.author_id) as Author,(select name from author_translators WHERE id = b.translate_id)as Translator,l.name as Language,pb.name as Publisher,b.publishing_date,b.edition,b.valume_number,b.ISBN from books b join categories c on b.category_id = c.id join publishers pb on b.publisher_id = pb.id join languages l on b.language_id = l.id')
                   ->paginate(5);     

Ссылка: https://laravel.com/docs/5.8/queries#selects

0 голосов
/ 26 марта 2020

Я нашел решение

try {
              $Book = \DB::table('books')
                    ->join('categories', 'categories.id', '=', 'books.category_id')
                    ->join('languages', 'languages.id', '=', 'books.language_id')
                    ->join('publishers', 'publishers.id', '=', 'books.publisher_id')  
                    ->join('author_translators as aa', 'aa.id', '=', 'books.author_id')
                     ->join('author_translators as at', 'at.id', '=', 'books.translate_id')          
                      ->select(
                'books.id as id',
                'books.name as bookname',
                'categories.name as category',
                'aa.name as Author',
                'at.name as Translator',
                'languages.name as Language',
                'publishers.name as Publisher',
                'books.publishing_date as publishing_date',
                'books.edition as edition',
                'books.valume_number as valume_number',
                'books.ISBN as ISBN '
            )->paginate(5);  


            return response()->json($Book);
        } catch (Exception $e) {
            return response()->json($e->getMessage(), 500);
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...