Files
UNIT3D-Community-Edition/app/Models/Movie.php
2022-09-30 16:46:38 -05:00

73 lines
2.2 KiB
PHP

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Movie extends Model
{
protected $guarded = [];
public $table = 'movie';
public function genres(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Genre::class);
}
public function cast(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Cast::class, 'cast_movie', 'cast_id', 'movie_id');
}
public function crew(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Crew::class, 'crew_movie', 'person_id', 'movie_id');
}
public function companies(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Company::class);
}
public function countries(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Company::class);
}
public function collection(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Collection::class)->take(1);
}
public function recommendations(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Recommendation::class, 'movie_id', 'id');
}
public function torrents(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(Torrent::class, 'tmdb', 'id')->whereHas('category', function ($q) {
$q->where('movie_meta', '=', true);
});
}
public function requests(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(TorrentRequest::class, 'tmdb', 'id')->whereHas('category', function ($q) {
$q->where('movie_meta', '-', true);
});
}
}