lots of progress

This commit is contained in:
2025-02-01 15:31:47 +02:00
parent 1362ceb642
commit 83b90aa7a0
40 changed files with 1046 additions and 44 deletions
+6 -1
View File
@@ -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');
}
}
+1 -1
View File
@@ -6,5 +6,5 @@ use Illuminate\Database\Eloquent\Model;
class Thread extends Model
{
//
protected $table = 'forum_threads';
}
+9
View File
@@ -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');
}
}
+26
View File
@@ -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')
+17
View File
@@ -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',
];
}