mirror of
https://github.com/devfake/flox.git
synced 2024-11-15 22:52:32 +01:00
5818026f67
* change parser fixtures * move alternativeTitle method to other class * refactor tests * start with alternative title * use app helper method * refactor add items * change fixtures structure * alternative title * episode service * item service * file parser test * flatten item controller * git ignorecase
91 lines
1.9 KiB
PHP
91 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Services\Storage;
|
|
use App\Services\TMDB;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Laravel\Scout\Searchable;
|
|
|
|
class Item extends Model {
|
|
|
|
// Uncomment this if you are using Laravel Scout.
|
|
//use Searchable;
|
|
|
|
public $timestamps = false;
|
|
|
|
protected $fillable = [
|
|
'tmdb_id',
|
|
'title',
|
|
'original_title',
|
|
'poster',
|
|
'media_type',
|
|
'rating',
|
|
'released',
|
|
'created_at',
|
|
'genre',
|
|
'src',
|
|
];
|
|
|
|
/**
|
|
* Create the new movie / tv show.
|
|
*
|
|
* @param $data
|
|
* @return Item
|
|
*/
|
|
public function store($data)
|
|
{
|
|
return $this->create([
|
|
'tmdb_id' => $data['tmdb_id'],
|
|
'title' => $data['title'],
|
|
'media_type' => $data['media_type'],
|
|
'original_title' => $data['original_title'],
|
|
'poster' => $data['poster'],
|
|
'rating' => 1,
|
|
'released' => $data['released'],
|
|
'genre' => $data['genre'],
|
|
'created_at' => time(),
|
|
]);
|
|
}
|
|
|
|
/*
|
|
* Relations
|
|
*/
|
|
|
|
public function episodes()
|
|
{
|
|
return $this->hasMany(Episode::class, 'tmdb_id', 'tmdb_id');
|
|
}
|
|
|
|
public function alternativeTitles()
|
|
{
|
|
return $this->hasMany(AlternativeTitle::class, 'tmdb_id', 'tmdb_id');
|
|
}
|
|
|
|
public function latestEpisode()
|
|
{
|
|
return $this->hasOne(Episode::class, 'tmdb_id', 'tmdb_id')
|
|
->orderBy('id', 'desc')
|
|
->where('seen', true)
|
|
->latest();
|
|
}
|
|
|
|
/*
|
|
* Scopes
|
|
*/
|
|
|
|
public function scopeFindByTmdbId($query, $tmdbId)
|
|
{
|
|
return $query->where('tmdb_id', $tmdbId);
|
|
}
|
|
|
|
public function scopeFindByTitle($query, $title)
|
|
{
|
|
return $query->where('title', 'like', '%' . $title . '%')
|
|
->orWhere('original_title', 'like', '%' . $title . '%')
|
|
->orWhereHas('alternativeTitles', function($query) use ($title) {
|
|
$query->where('title', 'like', '%' . $title . '%');
|
|
});
|
|
}
|
|
}
|