Reputation: 15
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
Upvotes: 0
Views: 1227
Reputation: 116
Try following query
$transactions = DB::table('transactions')->join('orders', 'transactions.order_id', '=', 'orders.id')->paginate(5);
remove get() from query
Upvotes: 3
Reputation: 1004
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]);
Upvotes: 0
Reputation: 12188
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);
Upvotes: 2