admin panel added and comments are working and likes are working

This commit is contained in:
ghassan committed 2026-03-03 17:36:19 +03:00
1 parent 72e9439727
commit a28023c29b
32 files changed
+5077 -2999

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $fillable = [
'video_id',
'user_id',
'parent_id',
'body',
];
// Relationships
public function video()
{
return $this->belongsTo(Video::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function parent()
{
return $this->belongsTo(Comment::class, 'parent_id');
}
public function replies()
{
return $this->hasMany(Comment::class, 'parent_id')->latest();
}
// Get mentioned users from comment body
public function getMentionedUsers()
{
preg_match_all('/@(\w+)/', $this->body, $matches);
if (empty($matches[1])) {
return collect();
}
return User::whereIn('username', $matches[1])->get();
}
// Parse mentions and make them clickable
public function getParsedBodyAttribute()
{
$body = e($this->body);
$body = preg_replace('/@(\w+)/', '<a href="/channel/$1" class="user-mention">@$1</a>', $body);
return $body;
}
}
+30
View File
@@ -14,9 +14,11 @@ class User extends Authenticatable
protected $fillable = [
'name',
'username',
'email',
'password',
'avatar',
'role',
];
protected $hidden = [
@@ -45,6 +47,11 @@ class User extends Authenticatable
return $this->belongsToMany(Video::class, 'video_views')->withTimestamps();
}
public function comments()
{
return $this->hasMany(Comment::class);
}
public function getAvatarUrlAttribute()
{
if ($this->avatar) {
@@ -52,5 +59,28 @@ class User extends Authenticatable
}
return 'https://i.pravatar.cc/150?u=' . $this->id;
}
// Role helper methods
public function isSuperAdmin()
{
return $this->role === 'super_admin';
}
public function isAdmin()
{
return in_array($this->role, ['admin', 'super_admin']);
}
public function isUser()
{
return $this->role === 'user' || $this->role === null;
}
// Placeholder for subscriber count (would need a separate table in full implementation)
public function getSubscriberCountAttribute()
{
// For now, return a placeholder - in production this would come from a subscriptions table
return rand(100, 10000);
}
}
+25 -4
View File
@@ -44,7 +44,9 @@ class Video extends Model
public function viewers()
{
return $this->belongsToMany(User::class, 'video_views')->withTimestamps();
return $this->belongsToMany(User::class, 'video_views')
->withPivot('watched_at')
->withTimestamps();
}
// Accessors
@@ -74,10 +76,10 @@ class Video extends Model
return $this->likes()->count();
}
// Get view count
// Get view count - use direct query to avoid timestamp issues
public function getViewCountAttribute()
{
return $this->viewers()->count();
return \DB::table('video_views')->where('video_id', $this->id)->count();
}
// Get shareable URL for the video
@@ -149,6 +151,15 @@ class Video extends Model
};
}
public function getTypeSymbolAttribute()
{
return match($this->type) {
'music' => '🎵',
'match' => '🏆',
default => '🎬',
};
}
public function isGeneric()
{
return $this->type === 'generic';
@@ -163,5 +174,15 @@ class Video extends Model
{
return $this->type === 'match';
}
}
// Comments relationship
public function comments()
{
return $this->hasMany(Comment::class)->latest();
}
public function getCommentCountAttribute()
{
return $this->comments()->count();
}
}