Skip to content

Instantly share code, notes, and snippets.

@pazteddy
Created July 8, 2026 16:38
Show Gist options
  • Select an option

  • Save pazteddy/47a09f8d2e8fdc9459ea25d8bdd99d41 to your computer and use it in GitHub Desktop.

Select an option

Save pazteddy/47a09f8d2e8fdc9459ea25d8bdd99d41 to your computer and use it in GitHub Desktop.
Recurso para películas
<?php
class MovieResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'synopsis' => $this->synopsis,
'year' => $this->year,
'rating' => $this->rating,
'director' => $this->director,
'duration' => $this->duration,
'poster_url' => $this->poster ? asset('storage/' . $this->poster) : null,
'is_active' => $this->is_active,
'genres' => GenreResource::collection($this->whenLoaded('genres')),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment