Files
shahrzadzandi09/app/Models/Favorite.php
T

56 lines
1.1 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
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 Model $favoritable
*
* @package App\Models
*/
class Favorite extends Model
{
protected $table = 'favorites';
public static $snakeAttributes = false;
protected $casts = [
'user_id' => 'int',
'favoritable_id' => 'int'
];
protected $fillable = [
'user_id',
'favoritable_id',
'favoritable_type'
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
// رابطه پلیمورفیک: علاقهمندی میتونه به محصول، خبر، پست و... وصل باشه
public function favoritable(): MorphTo
{
return $this->morphTo();
}
}