Files

37 lines
735 B
PHP

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