usama shakeel
usama shakeel

Reputation: 15

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

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

Answers (3)

Raj Vadi
Raj Vadi

Reputation: 116

Try following query

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

remove get() from query

Upvotes: 3

Zia Yamin
Zia Yamin

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

OMR
OMR

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

Related Questions