<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Basket extends Model
{
    protected $fillable = [
        'id', 'cart_data',
    ];

    protected $guarded = ['id'];

    protected $table = 'shop_baskets';

    public function Offer(): BelongsTo
    {
        return $this->belongsTo(Offer::class);
    }

    public function setCartDataAttribute($value)
    {
        $this->attributes['cart_data'] = serialize($value);
    }

    public function getCartDataAttribute($value)
    {
        return unserialize($value);
    }
}
