<?php

namespace App\Models\Traits;

use App\Models\Account;

trait HasAccount
{

    /**
     * @var array
     */
    public static function bootHasAccount()
    {
        self::created(function ($model) {
            $model->account()->create();
        });

        self::deleting(function ($model) {
            $model->account()->delete();
        });

        //        self::retrieved(function($model) {
        //            if (!$model->account) {
        //                $model->account()->create();
        //            }
        //        });
    }

    public function account()
    {
        return $this->morphOne(Account::class, 'accountable');
    }

}
