1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Illuminate\Support\Facades\Cache; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* App\Models\MovieInfo. |
10
|
|
|
* |
11
|
|
|
* @property int $id |
12
|
|
|
* @property int $imdbid |
13
|
|
|
* @property int $tmdbid |
14
|
|
|
* @property string $title |
15
|
|
|
* @property string $tagline |
16
|
|
|
* @property string $rating |
17
|
|
|
* @property string $rtrating RottenTomatoes rating score |
18
|
|
|
* @property string $plot |
19
|
|
|
* @property string $year |
20
|
|
|
* @property string $genre |
21
|
|
|
* @property string $type |
22
|
|
|
* @property string $director |
23
|
|
|
* @property string $actors |
24
|
|
|
* @property string $language |
25
|
|
|
* @property bool $cover |
26
|
|
|
* @property bool $backdrop |
27
|
|
|
* @property \Carbon\Carbon|null $created_at |
28
|
|
|
* @property \Carbon\Carbon|null $updated_at |
29
|
|
|
* @property string $trailer |
30
|
|
|
* |
31
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereActors($value) |
32
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereBackdrop($value) |
33
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereCover($value) |
34
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereCreatedAt($value) |
35
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereDirector($value) |
36
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereGenre($value) |
37
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereId($value) |
38
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereImdbid($value) |
39
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereLanguage($value) |
40
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo wherePlot($value) |
41
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereRating($value) |
42
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereRtrating($value) |
43
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereTagline($value) |
44
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereTitle($value) |
45
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereTmdbid($value) |
46
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereTrailer($value) |
47
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereType($value) |
48
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereUpdatedAt($value) |
49
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereYear($value) |
50
|
|
|
* |
51
|
|
|
* @mixin \Eloquent |
52
|
|
|
* |
53
|
|
|
* @property int $traktid |
54
|
|
|
* |
55
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo newModelQuery() |
56
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo newQuery() |
57
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo query() |
58
|
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\MovieInfo whereTraktid($value) |
59
|
|
|
*/ |
60
|
|
|
class MovieInfo extends Model |
61
|
|
|
{ |
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
protected $table = 'movieinfo'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var bool |
69
|
|
|
*/ |
70
|
|
|
protected $dateFormat = false; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
protected $guarded = ['id']; |
76
|
|
|
|
77
|
|
|
public static function getAll(string $search = ''): mixed |
78
|
|
|
{ |
79
|
|
|
$expiresAt = now()->addMinutes(config('nntmux.cache_expiry_medium')); |
80
|
|
|
$movie = Cache::get(md5($search)); |
81
|
|
|
if ($movie !== null) { |
82
|
|
|
return $movie; |
83
|
|
|
} |
84
|
|
|
$sql = self::query()->leftJoin('releases', 'releases.imdbid', '=', 'movieinfo.imdbid')->orderByDesc('movieinfo.created_at'); |
|
|
|
|
85
|
|
|
if (! empty($search)) { |
86
|
|
|
$sql->whereLike('movieinfo.title', $search); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$movie = $sql->paginate(config('nntmux.items_per_page')); |
90
|
|
|
Cache::put(md5($search), $movie, $expiresAt); |
91
|
|
|
|
92
|
|
|
return $movie; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|