AttachmentResource.php 982 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use Illuminate\Support\Facades\Storage;
  5. class AttachmentResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  12. */
  13. public function toArray($request)
  14. {
  15. $data = [
  16. "id" => $this->id,
  17. "user_uid" => $this->user_uid,
  18. "name" => $this->bucket.'/'.$this->name,
  19. "filename" => $this->bucket.'/'.$this->name,
  20. "title" => $this->title,
  21. "size" => $this->size,
  22. "content_type" => $this->content_type,
  23. "url" => Storage::url($this->bucket.'/'.$this->name),
  24. "status" => $this->status,
  25. "created_at" => $this->created_at,
  26. "updated_at" => $this->updated_at,
  27. ];
  28. return $data;
  29. }
  30. }