我的代码在此处按dateOrder排序分页,并且dateOrder在“我的模型”中,追加如何不对每30条记录的所有结果进行排序
$posts = Post::paginate(30)->sortByDesc('dateOrder');
protected $appends =['dateOrder'];
public function getdateOrderAttribute()
{
if($this->add_date && is_null($this->updated_at) )
return Carbon::createFromTimestamp($this->add_date)->toDateTimeString();
return ($this->updated_at)->toDateTimeString();
}
答案 0 :(得分:0)
尝试以下代码:
$posts = Post::paginate(30)->sortByDesc('date_order');
protected $appends =['dateOrder'];
public function getdateOrderAttribute()
{
if($this->add_date && is_null($this->updated_at) ){
return Carbon::createFromTimestamp($this->add_date)->toDateTimeString();
} else {
return $this->updated_at->toDateTimeString();
}
}
我希望它会有所帮助。