我正在使用Laravel5.0。我想将paginate()
添加到控制器部分的以下功能中。
public function index()
{
try{
$val=DB::connection()->getDatabaseName();
if(DB::connection()->getDatabaseName()) {
//$bRecord = DB::table('bills')->orderBy('Date', 'desc')->paginate(4);
$bRecord = DB::table('bills')
->join('clients', 'bills.ClientID', '=', 'clients.ClientID')
->select('bills.ReceiptID', 'bills.ClientID', 'bills.Paid', 'bills.Date','bills.ReceivedBy',
'clients.ClientName')
->get();
return view('bills.billRecord')->with('bRecord', $bRecord);
}else{
$er="/connection status: database error";
return view('home')->with('error',$er); //'error' is passed to home
}
}catch (\Exception $e){
$er="/connection status: database error";
return view('home')->with('error',$er);
}
}
如果我在此处添加分页显示错误。 “在数组上调用成员函数paginate()”
$bRecord = DB::table('bills')
->join('clients', 'bills.ClientID', '=', 'clients.ClientID')
->select('bills.ReceiptID', 'bills.ClientID', 'bills.Paid', 'bills.Date','bills.ReceivedBy',
'clients.ClientName')
->get()->paginate(4);
如何在这里使用paginate()
?
参考方案
Laravel 5.0 Pagination documentation:中的示例
$users = DB::table('users')->paginate(15);
因此,请尝试将示例的最后一行从
->get()->paginate(4);
至
->paginate(4);
PHP Laravel从另一个驱动器读取文件 - php我目前正在学习Laravel。我想知道是否有一种方法可以在Laravel中使用Storage::从另一个硬盘访问文件(使用Windows)。例如,我在驱动器C:上安装了带有Laravel的Xampp,但是我想访问网站目录之外的E:上的文件。我试过使用Storage::files('E:')和File::files('E:…
Laravel 5排序具有关系的雄辩模型 - php我有一个要基于关系属性进行排序的模型。主模型Resultado具有类型respondente的关系belongsTo,而respondente具有关系usuario。我想获取具有这些关系的Resultado并按usuario name属性(列)对结果进行排序。我试过了$resultados = Diagnostico\Resultado::with(…
检查对象是否已在集合中-Laravel - php当我循环一系列不同的结果时,我希望将对象添加到新集合中。查询:$osRed = Item::where('category', 'Hardware') ->where(function ($query) { $query->where('operating_system', '…
Laravel-使用雄辩的语言在开始日期和结束日期之间选择行 - php我想将此查询转换为雄辩的laravel,select * from schedule where (now() between start_date and end_date); 我尝试使用whereBetween,但是出现了一些错误。$schedule = Schedule::whereBetween(Carbon::now(), ['start…
PHP strtotime困境 - php有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00…