Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel-4 Pagination in Query Builder

How to enable pagination in laravel-4.1 when using query builder.

Here is my function from model.

public static function getTransactions( $accountCode ) {
        $accountId = Account::getAccountId( $accountCode );
        $object = DB::table('transactions')
            ->orderBy('transactionId', 'ASC')
            ->where('fkAccountId', $accountId)
            ->where('fkUserId', Auth::user()->userId);
            ->get();

        return $object;
    }
like image 281
zarpio Avatar asked Mar 20 '23 14:03

zarpio


1 Answers

public static function getTransactions( $accountCode ) {
        $accountId = Account::getAccountId( $accountCode );
        $object = DB::table('transactions')
            ->orderBy('transactionId', 'ASC')
            ->where('fkAccountId', $accountId)
            ->where('fkUserId', Auth::user()->userId);
            ->paginate(10);

        return $object;
    }

and

echo $object->links(); //links

http://laravel.com/docs/pagination#usage

like image 56
Nostalgie Avatar answered Mar 31 '23 18:03

Nostalgie