我正在尝试对来自 Controller 的订单进行分页
$orders = Order::openorders()->paginate(15);
在模型中我有这个:
public static function stats()
{
return Stats::where(\DB::raw('SUBSTRING(statistics, 5, 5)'), '!=','D')->where('statistics', 'NOT LIKE', '%F%')->where('statistics', 'NOT LIKE', '%X%')->get()->sortByDesc('date');
}
它正在显示这条消息:
(1/1) BadMethodCallException
Method paginate does not exist.
最佳答案
方法链接指的是this
你不能像这样链接静态和公共(public)方法但是你可以利用scopes() .
像这样更改您的方法的名称。
public function scopeOpenorders($query)
{
return $query->where(\DB::raw('SUBSTRING(cu_stat, 1, 1)'), '!=','C')
->where('cu_stat', 'NOT LIKE', '%D%')->where('cu_stat', 'NOT LIKE', '%X%')
->orderBy('cu_date','DESC');
}
您可以在此处了解有关范围的更多信息 https://laravel.com/docs/5.6/eloquent#local-scopes
希望这对您有所帮助。
关于php - Laravel - 方法分页不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50852160/