Reputation: 7338
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;
}
Upvotes: 4
Views: 1806
Reputation: 19
if you accede to your model via your controller before returning the view, make :
abstract class YourController extends \BaseController {
public function index() {
$modelManager = new yourModel();
$pagination = $modelManager->getTransactions($accountCode)->links();
return View::make('yourView', array('pagination' => $pagination));
}
}
and use {{$pagination}}
in your view.
Upvotes: 0
Reputation: 15653
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(NUMBER OF PAGES); // whatever you needs this to be
return $object;
}
Upvotes: 3
Reputation: 564
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
Upvotes: 4