如何在使用查询构建器时在laravel-4.1中启用分页。
这是我的模特功能。
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;
}
答案 0 :(得分:4)
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;
}
和
echo $object->links(); //links
答案 1 :(得分:3)
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;
}
答案 2 :(得分:0)
如果您在返回视图之前通过控制器加入模型,请执行:
abstract class YourController extends \BaseController {
public function index() {
$modelManager = new yourModel();
$pagination = $modelManager->getTransactions($accountCode)->links();
return View::make('yourView', array('pagination' => $pagination));
}
}
并在您的视图中使用{{$pagination}}
。