belongsTo(Company::class); } public function user() { return $this->belongsTo(User::class); } public function deals() { return $this->hasMany(Deal::class); } protected static function booted(): void { static::created(function (Agent $agent) { UserRole::create([ 'user_id' => $agent->user_id, 'role_id' => Role::AGENT ]); $agent->notify(); }); static::updated(function (Agent $agent) { if ($agent->trashed()) { UserRole::where([ 'user_id' => $agent->user_id, 'role_id' => Role::AGENT ])->delete(); } else { UserRole::create([ 'user_id' => $agent->user_id, 'role_id' => Role::AGENT ]); } }); } private function notify() { $this->user->notify(new AgentCreated($this)); return true; } }