mirror of
https://github.com/m1ngsama/php.git
synced 2025-12-24 16:01:19 +00:00
Added Community, Post, Comment, and Vote models with proper relationships. Updated User model to include karma field and forum-related relationships.
56 lines
1,018 B
PHP
56 lines
1,018 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Comment extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'post_id',
|
|
'user_id',
|
|
'parent_id',
|
|
'content',
|
|
'votes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'votes' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function post()
|
|
{
|
|
return $this->belongsTo(Post::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');
|
|
}
|
|
|
|
public function votes()
|
|
{
|
|
return $this->morphMany(Vote::class, 'voteable');
|
|
}
|
|
|
|
public function userVote($userId)
|
|
{
|
|
return $this->votes()->where('user_id', $userId)->first();
|
|
}
|
|
}
|