fix! вывод привязанных агентсв в карточке редактирования пользователя

This commit is contained in:
developer 2026-01-22 16:32:54 +08:00
parent 0adf50bfb5
commit 9f435e0816
2 changed files with 25 additions and 2 deletions

View File

@ -51,14 +51,14 @@
@if($userRole->role->id == $roles::COMPANY_ADMIN)
<div class="fs-6 hstack gap-1">
@foreach($companyAdmins as $admin)
<span class="badge text-bg-secondary">{{ $admin->company->name }}</span>
<span class="badge text-bg-secondary">{{ $admin->company?->name }}</span>
@endforeach
</div>
@endif
@if($userRole->role->id == $roles::AGENT)
<div class="fs-6 hstack gap-1">
@foreach($companyAgents as $agent)
<span class="badge text-bg-secondary">{{ $agent->company->name }}</span>
<span class="badge text-bg-secondary">{{ $agent->company?->name }}</span>
@endforeach
</div>
@endif

View File

@ -7,6 +7,10 @@
use Modules\User\Models\User;
use Modules\User\Models\Role;
use Modules\Main\Models\Company\CompanyAdmin;
use Modules\Main\Models\Agent\Agent;
use Modules\CityManager\Models\CityManager;
class UserRole extends Model
{
use HasFactory;
@ -24,4 +28,23 @@ public static function create(array $attributes = [])
{
return parent::updateOrCreate($attributes);
}
protected static function booted()
{
static::deleted(function (UserRole $userRole)
{
$userId = $userRole->user_id;
switch ($userRole->role_id) {
case Role::AGENT :
Agent::where('user_id', $userId)->delete();
break;
case Role::COMPANY_ADMIN :
CompanyAdmin::where('user_id', $userId)->delete();
break;
case Role::CITY_MANAGER :
CityManager::where('user_id', $userId)->delete();
break;
}
});
}
}