我getCanSeeAttribute
在帖子模型中有功能,我尝试使用分页获取帖子filter()
$posts = Post::where(function ($query1) use ($users) {
$query1->where('posted_type', 'user')->whereIn('posted_id', $users);
})
->orWhere(function ($query2) use ($stores) {
$query2->where('posted_type', 'store')->whereIn('posted_id', $stores);
})
->with('likes', 'postable')
->withCount('comments', 'likes')
->latest()->paginate($paginate)->filter(function($post){
return $post->can_see == true;
});
问题是当我使用过滤器时,它只获取数据属性,但我需要所有分页属性。
first_page_url": "http://localhost:8000/api/timeline?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://localhost:8000/api/timeline?page=1",
"next_page_url": null,
"path": "http://localhost:8000/api/timeline",
"per_page": 10,
"prev_page_url": null,
"to": 6,
"total": 6
can_see 不是表中的列,它是访问器