Files
pingan_new/app/Models/Traits/HasAccount.php
2020-08-06 16:42:18 +08:00

36 lines
674 B
PHP

<?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');
}
}