lots of progress
This commit is contained in:
@@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'forum_categories';
|
||||
|
||||
public function threads()
|
||||
{
|
||||
return $this->hasMany(Thread::class, 'category_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Thread extends Model
|
||||
{
|
||||
//
|
||||
protected $table = 'forum_threads';
|
||||
}
|
||||
|
||||
@@ -12,4 +12,13 @@ class MediaListItem extends Model
|
||||
'item_type',
|
||||
'tmdb_id',
|
||||
];
|
||||
|
||||
public function item()
|
||||
{
|
||||
if ($this->item_type == 'movie') {
|
||||
return $this->hasOne(Movie::class, 'id', 'item_id');
|
||||
}
|
||||
|
||||
return $this->hasOne(Show::class, 'id', 'item_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,32 @@ class Movie extends Model
|
||||
'release_date' => 'date'
|
||||
];
|
||||
|
||||
public function wasListedBy(string $listSlug, User $user)
|
||||
{
|
||||
$mediaList = MediaList::where('slug', $listSlug)->where('user_id', $user->id)->first();
|
||||
|
||||
if ($mediaList) {
|
||||
$mediaListItem = MediaListItem::where('media_list_id', $mediaList->id)
|
||||
->where('item_id', $this->id)
|
||||
->where('item_type', 'movie')
|
||||
->first();
|
||||
|
||||
return !empty($mediaListItem);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function ratingBy(User $user)
|
||||
{
|
||||
$rating = Rate::where('user_id', $user->id)
|
||||
->where('item_id', $this->id)
|
||||
->where('item_type', 'movie')
|
||||
->first();
|
||||
|
||||
return $rating ? $rating->rate : null;
|
||||
}
|
||||
|
||||
public function director()
|
||||
{
|
||||
return $this->belongsToMany(Person::class, 'movie_cast', 'movie_id', 'person_id')
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Rate extends Model
|
||||
{
|
||||
protected $table = 'ratings';
|
||||
|
||||
protected $fillable = [
|
||||
'item_id',
|
||||
'item_type',
|
||||
'rate',
|
||||
'user_id',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user