回复列表接口显示能否删除 有没有更好的方案
class ReplyResource extends JsonResource
{
public function toArray($request)
{
return [
.
.
.
'delete'=>$this->canDelete(),
];
}
protected function canDelete(){
$reply = Reply::find($this->id);
return (new ReplyPolicy())->destroy(auth('api')->user(),$reply);
}
}
delete 字段判断是否可以删除的方法是否合理
推荐文章: