我有一个问题,我尝试通过Resource API获取带有已删除帖子的帖子列表。这里的代码示例
public function index(Request $request)
{
$perPage = (int) $request->get('per_page');
if ($perPage < 1 or $perPage > 1000) {
$perPage = config('database.paginate');
}
$clubId = (int)$request->get('club');
$query = Playground::query();
if ($clubId) {
$query = $query->where('club_id', $clubId);
}
return PlaygroundResource::collection($query->paginate($perPage));
}
我无法在集合中添加->withTrashed()
方法,那么如何获得所有帖子?
UPD :: 游乐场模型
protected $fillable = [
'slug',
'name',
'club_id',
'links',
'playground_types',
'services',
'equipments',
'surfaces',
'sports',
'type',
'description'
];
protected $dates = ['deleted_at'];
答案 0 :(得分:3)
您是否尝试过将->withTrashed()
放在$query
后面?例如,在您定义它之后?
$query = Playground::query();
$query->withTrashed();