Files
back-meditation/app/Models/Comment.php
T

38 lines
766 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Comment extends Model
{
protected $fillable = [
'user_id',
'commentable_id',
'commentable_type',
'content',
];
public function user()
{
return $this->belongsTo(User::class);
}
public function commentable()
{
return $this->morphTo();
}
// For backward compatibility with Media
public function media()
{
return $this->belongsTo(Media::class, 'commentable_id')->where('commentable_type', Media::class);
}
// For Music
public function music()
{
return $this->belongsTo(Music::class, 'commentable_id')->where('commentable_type', Music::class);
}
}