fix: correct polymorphic relations in comment, favorite and payment models

This commit is contained in:
2026-08-17 08:13:02 +03:30
parent 42be8ce894
commit ed02b45269
3 changed files with 82 additions and 74 deletions
+25 -29
View File
@@ -7,53 +7,49 @@
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* Class Favorite
*
*
* @property int $id
* @property int $user_id
* @property int $favoritable_id
* @property string $favoritable_type
* @property Carbon $created_at
* @property Carbon $updated_at
*
*
* @property User $user
* @property Favorite $favorite
* @property Collection|Favorite[] $favorites
* @property Model $favoritable
*
* @package App\Models
*/
class Favorite extends Model
{
protected $table = 'favorites';
public static $snakeAttributes = false;
protected $table = 'favorites';
public static $snakeAttributes = false;
protected $casts = [
'user_id' => 'int',
'favoritable_id' => 'int'
];
protected $casts = [
'user_id' => 'int',
'favoritable_id' => 'int'
];
protected $fillable = [
'user_id',
'favoritable_id',
'favoritable_type'
];
protected $fillable = [
'user_id',
'favoritable_id',
'favoritable_type'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function favorite()
{
return $this->belongsTo(Favorite::class, 'favoritable_id');
}
public function favorites()
{
return $this->hasMany(Favorite::class, 'favoritable_id');
}
// رابطه پلیمورفیک: علاقهمندی میتونه به محصول، خبر، پست و... وصل باشه
public function favoritable(): MorphTo
{
return $this->morphTo();
}
}