<?php

namespace App\Traits;

use App\Models\Phone;

trait Phonable
{

    public function addPhone(array $phone)
    {

        count($this->phone()->get()) ? $this->phone()->update(
            [
                'phone' => $phone['number'],
                'code' => $phone['code'] ?? 'EG',
            ]
        ) : $this->phone()->create(
            [
                'phone' => $phone['number'],
                'code' => $phone['code'] ?? 'EG',
            ]
        );


    }

    public function phone()
    {
        return $this->morphOne(Phone::class, 'phoneable');
    }
}
