48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||
|
|
|
||
|
|
class Movie extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = [
|
||
|
|
'title',
|
||
|
|
'imdb_id',
|
||
|
|
'year',
|
||
|
|
'director',
|
||
|
|
'actors',
|
||
|
|
'plot',
|
||
|
|
'genre',
|
||
|
|
'mpaa_rating',
|
||
|
|
'critic_scores',
|
||
|
|
'poster',
|
||
|
|
'added_by',
|
||
|
|
];
|
||
|
|
|
||
|
|
public static function fromOmdb(array $omdb): self
|
||
|
|
{
|
||
|
|
$attributes = [
|
||
|
|
'title' => $omdb['Title'],
|
||
|
|
'imdb_id' => $omdb['imdbID'],
|
||
|
|
'year' => $omdb['Year'],
|
||
|
|
'director' => $omdb['Director'],
|
||
|
|
'actors' => $omdb['Actors'],
|
||
|
|
'plot' => $omdb['Plot'],
|
||
|
|
'genre' => $omdb['Genre'],
|
||
|
|
'mpaa_rating' => $omdb['Rated'],
|
||
|
|
'critic_scores' => json_encode($omdb['Ratings']),
|
||
|
|
'poster' => $omdb['Poster'],
|
||
|
|
'added_by' => $omdb['added_by'],
|
||
|
|
];
|
||
|
|
|
||
|
|
return static::create($attributes);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function movieLists(): belongsToMany
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(MovieList::class);
|
||
|
|
}
|
||
|
|
}
|