| 1234567891011121314151617181920212223242526272829 |
- <?php
- namespace App\Http\Resources;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- use Illuminate\Support\Facades\Storage;
- class MediaResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'type' => $this->type,
- 'source' => $this->source,
- 'source_id' => $this->source_id,
- 'path' => $this->path,
- 'name' => $this->name,
- 'url' => $this->path
- ? Storage::disk('s3')->temporaryUrl($this->path, now()->addHours(24))
- : null,
- 'user_id' => $this->user_id,
- 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
- 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
- ];
- }
- }
|