20 lines
713 B
PHP
20 lines
713 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Builder;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
|
|
|
||
|
|
class GameComment extends Model
|
||
|
|
{
|
||
|
|
protected $fillable = ['user_id', 'game_id', 'parent_id', 'body'];
|
||
|
|
|
||
|
|
public function user(): BelongsTo { return $this->belongsTo(User::class); }
|
||
|
|
public function game(): BelongsTo { return $this->belongsTo(Game::class); }
|
||
|
|
public function replies(): HasMany { return $this->hasMany(GameComment::class, 'parent_id')->with('user')->latest(); }
|
||
|
|
|
||
|
|
public function scopeTopLevel(Builder $query): Builder { return $query->whereNull('parent_id'); }
|
||
|
|
}
|