【发布时间】:2021-04-07 12:31:25
【问题描述】:
我想按天对我的帖子进行分组,按最新排序,并为一个时间轴添加分页,该时间轴还将在前端包含无限滚动的 vue spa:
记录控制器
public function userFeed($userId)
{
$client = User::where('hashed_id', $userId)->first();
$records = Record::where('user_id', $client->id)->latest()->paginate(10);
return RecordResource::collection($records);
}
记录资源
class RecordResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->hashed_id,
'owner' => new UserResource($this->owner),
'title' => $this->title,
'created_at' => $this->created_at->format('M d Y'),
'comments' => $this->decryptedComments()
];
}
}
我希望 API 的布局便于使用 v-for 循环:
[
'Sunday' => 5,
'Monday' => 45,
'Tuesday' => 452,
...
]
<div v-for="(record, index) in records" v-bind:key="index" class="mb-10">
<div class="card>
<h1>{{record.title}}</h1>
</div>
</div>
【问题讨论】:
-
大部分变化to this thread
-
"message": "stripos() expects parameter 1 to be string, object given", -
试试
$records = Record::where('user_id', $client->id)->latest()->paginate(10)->groupBy('created_at'); -
我仍然遇到同样的错误
-
stripos()这是不同的错误,它与 group by 无关