2016-12-17 16:59:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class AlternativeTitle extends Model {
|
|
|
|
|
|
|
|
public $timestamps = false;
|
|
|
|
|
2017-01-06 13:00:18 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'title',
|
|
|
|
'tmdb_id',
|
2017-01-23 22:26:04 +01:00
|
|
|
'country',
|
2017-01-06 13:00:18 +01:00
|
|
|
];
|
2017-01-06 09:40:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Store all alternative titles for tv shows and movies.
|
|
|
|
*
|
2017-01-23 22:26:04 +01:00
|
|
|
* @param $titles
|
|
|
|
* @param $tmdbId
|
2017-01-06 09:40:27 +01:00
|
|
|
*/
|
2017-01-23 22:26:04 +01:00
|
|
|
public function store($titles, $tmdbId)
|
2017-01-06 09:40:27 +01:00
|
|
|
{
|
2017-01-23 22:26:04 +01:00
|
|
|
foreach($titles as $title) {
|
2017-01-06 09:40:27 +01:00
|
|
|
$this->firstOrCreate([
|
|
|
|
'title' => $title->title,
|
2017-01-23 22:26:04 +01:00
|
|
|
'tmdb_id' => $tmdbId,
|
2017-01-06 09:40:27 +01:00
|
|
|
'country' => $title->iso_3166_1,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2017-01-23 22:26:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scopes
|
|
|
|
*/
|
|
|
|
public function scopeFindByTmdbId($query, $tmdbId)
|
|
|
|
{
|
|
|
|
return $query->where('tmdb_id', $tmdbId);
|
|
|
|
}
|
2016-12-17 16:59:59 +01:00
|
|
|
}
|