因此,我知道如何使用paginate()分页,并知道如何基于 (集合上的where() )进行筛选。但是,分页获取查询生成器,集合上的where()返回集合。
因此,如果我想通过自定义属性获得一组项/筛选器,然后分页结果set....how,我会这样做吗??
访问者:
public function getRequiredToReportAttribute()
{
// return boolean based off of complicated business logic
}
指数法:
public function index()
{
//what im doing (re
我正在使用Laravel雄辩的懒散、急切的加载特性,首先查询一些payments,然后使用->load()将payers加载到每个payment中。
澄清: users hasMany payers hasAndBelongsToMany payments
下面是我使用的代码(花了一段时间才弄清楚,但它有效)
//Get all the payments for the logged in user
$payments = Payment::whereHas('payers', function($q){
$q->where('
我试图在Laravel中对分页查询结果进行排序。我需要做一种排序,在每样东西的末尾降到我的分页变量上。
示例:
//get some data attach to variable
$variable = DB::table('exampletable')
->where('id',$somevariable)
->select('id','name')
->paginate(10);
//this function will send the variable and attach **total** on
我有一个新闻表,并管理已读或未读标志。所以我想对这两个标志进行分页,而不需要额外的数据库查询。我的要求是获取所有新闻,并对单独的表视图进行已读或未读的筛选和分页。我尝试了以下代码,但得到了一个错误的Method Illuminate\Database\Eloquent\Collection::paginate does not exist.
$ns=News::all();
$ns->where('read',1)->paginate(2);
$ns->where('read',0)->paginate(2);
我
我正在处理一个项目,我希望使用where子句,分页,然后按特定顺序在集合中排序。我尝试了下面的结果,但是一直把错误抛在方法下面:
不存在Illuminate\Database\Eloquent\Collection::links 。(浏览: /Applications/XAMPP/xamppfiles/htdocs/vermex/resources/views/equipments.blade.php)
产品模型是我获取数据并存储在一个名为$equipment的变量中的地方。如果有更好的方法,请帮助。
public function equipments()
{
$e
我想知道如何在Laravel中分页调用关系的数据,我不想在同一条路径上加载所有的信息,这样会使负载更重。
我有类别和产品,在资源类别中,我通过关系调用产品,但我需要做的是对这些产品进行分页。
我需要在路由api/分类/1中,它返回类别的名称和特定类别上的产品(它正在工作),但是需要分页的那些产品。
在我的类别控制器中:
public function show($id)
{
$category = Category::findOrFail($id);
return new CategoryResource($category);
}
在我的分类模型中,我有:
public
我试图对一个雄辩的事物进行分页,但我无法使它发挥作用。分页引发错误,因为$products不是查询生成器对象,而是集合。
// i get this value from a $POST variable
$customOrderIds = [3,2,1,4,6,5,9,8,10,7,11,12,13,14,15,16,17,20,18,19,21,22]; // I want the products ordered in this sequence
$products = Product::get()->sortBy(function($product) use($customOrd