MediaResource.php 961 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Illuminate\Support\Facades\Storage;
  7. class MediaResource extends JsonResource
  8. {
  9. public function toArray(Request $request): array
  10. {
  11. return [
  12. 'id' => $this->id,
  13. 'type' => $this->type,
  14. 'source' => $this->source,
  15. 'source_id' => $this->source_id,
  16. 'path' => $this->path,
  17. 'name' => $this->name,
  18. 'url' => $this->path
  19. ? Storage::disk('s3')->temporaryUrl($this->path, now()->addHours(24))
  20. : null,
  21. 'user_id' => $this->user_id,
  22. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  23. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  24. ];
  25. }
  26. }