|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Resources; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Movie API Resource for transforming movie data. |
|
10
|
|
|
*/ |
|
11
|
|
|
class MovieResource extends JsonResource |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* Transform the resource into an array. |
|
15
|
|
|
* |
|
16
|
|
|
* @return array<string, mixed> |
|
17
|
|
|
*/ |
|
18
|
|
|
public function toArray(Request $request): array |
|
19
|
|
|
{ |
|
20
|
|
|
return [ |
|
21
|
|
|
'id' => $this->id, |
|
|
|
|
|
|
22
|
|
|
'imdbid' => $this->imdbid, |
|
|
|
|
|
|
23
|
|
|
'tmdbid' => $this->tmdbid, |
|
|
|
|
|
|
24
|
|
|
'traktid' => $this->traktid, |
|
|
|
|
|
|
25
|
|
|
'title' => $this->title, |
|
|
|
|
|
|
26
|
|
|
'year' => $this->year, |
|
|
|
|
|
|
27
|
|
|
'rating' => $this->rating, |
|
|
|
|
|
|
28
|
|
|
'rtrating' => $this->rtrating, |
|
|
|
|
|
|
29
|
|
|
'tagline' => $this->tagline, |
|
|
|
|
|
|
30
|
|
|
'plot' => $this->plot, |
|
|
|
|
|
|
31
|
|
|
'genre' => $this->genre, |
|
|
|
|
|
|
32
|
|
|
'type' => $this->type, |
|
|
|
|
|
|
33
|
|
|
'director' => $this->director, |
|
|
|
|
|
|
34
|
|
|
'actors' => $this->actors, |
|
|
|
|
|
|
35
|
|
|
'language' => $this->language, |
|
|
|
|
|
|
36
|
|
|
'cover' => $this->cover ? true : false, |
|
|
|
|
|
|
37
|
|
|
'backdrop' => $this->backdrop ? true : false, |
|
|
|
|
|
|
38
|
|
|
'trailer' => $this->trailer, |
|
|
|
|
|
|
39
|
|
|
'cover_url' => $this->getCoverUrl(), |
|
40
|
|
|
'backdrop_url' => $this->getBackdropUrl(), |
|
41
|
|
|
'imdb_url' => $this->imdbid ? 'https://www.imdb.com/title/tt'.$this->imdbid.'/' : null, |
|
42
|
|
|
'created_at' => $this->created_at?->toIso8601String(), |
|
|
|
|
|
|
43
|
|
|
'updated_at' => $this->updated_at?->toIso8601String(), |
|
|
|
|
|
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the cover image URL. |
|
49
|
|
|
*/ |
|
50
|
|
|
protected function getCoverUrl(): ?string |
|
51
|
|
|
{ |
|
52
|
|
|
if (! $this->cover || ! $this->imdbid) { |
|
|
|
|
|
|
53
|
|
|
return null; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return url('/covers/movies/'.$this->imdbid.'-cover.jpg'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get the backdrop image URL. |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getBackdropUrl(): ?string |
|
63
|
|
|
{ |
|
64
|
|
|
if (! $this->backdrop || ! $this->imdbid) { |
|
|
|
|
|
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return url('/covers/movies/'.$this->imdbid.'-backdrop.jpg'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
|