<?php

namespace Modules\Plan7\Traits;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Plan7\Models\DealPlan7;
use Modules\Main\Models\Deal\Deal;
trait Plan7Deal
{
    protected $bitrixData = [];
    public function setPlan7Data($id, $data)
    {
        return DealPlan7::updateOrCreate(['deal_id' => $this->id], [
            'plan7_id' => $id,
            'data' => json_encode($data)
        ]);
    }
    public function getPlan7Data()
    {
        if ($plan7 = DealPlan7::where('deal_id', $this->id)->first()) {
            return $plan7->data;
        }
        return [];
    }
}


