0
votes

I have this code:

$transactions = DB::table('transactions')
        ->join('orders', 'transactions.order_id', '=', 'orders.id')
        ->get()->paginate(5);


return view('transactions.index', ['transactions' => $transactions]);

the code result in this error:

Method Illuminate\Support\Collection::paginate does not exist

3
I'm not sure but just try to remove get() method and use paginate(5) only. Hope it will help you. Because there was some return type issue. - Kaushik shrimali
->get() returns collection while ->paginate() asks for query builder. - Tpojka

3 Answers

2
votes

Laravel collection deosn't support pagination, but db query does, so you have to tell your query to paginate not the collection:

$transactions = DB::table('transactions')
        ->join('orders', 'transactions.order_id', '=', 'orders.id')->paginate(5);
2
votes

Try following query

 $transactions = DB::table('transactions')->join('orders', 'transactions.order_id', '=', 'orders.id')->paginate(5);

remove get() from query

0
votes

you can not use paginate after get method, use the below code

$transactions = DB::table('transactions')
    ->join('orders', 'transactions.order_id', '=', 'orders.id')
    ->paginate(5);
return view('transactions.index', ['transactions' => $transactions]);