Feat: searchable-select для организации в пользователях

 edit.blade.php — выбор организации через searchable-select
 create.blade.php — выбор организации через searchable-select
 Контроллер не передаёт $organizations

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad 2026-03-30 15:43:14 +08:00
parent f8fc503177
commit 2e1fdee017
3 changed files with 16 additions and 18 deletions

View File

@ -50,11 +50,10 @@ class UserController extends Controller
public function create() public function create()
{ {
Gate::authorize('create', User::class); Gate::authorize('create', User::class);
$organizations = Organization::pluck('name', 'id');
$roles = Role::pluck('name', 'name'); $roles = Role::pluck('name', 'name');
return view('admin.users.create', compact('organizations', 'roles')); return view('admin.users.create', compact('roles'));
} }
public function store(Request $request) public function store(Request $request)
@ -100,7 +99,6 @@ class UserController extends Controller
Gate::authorize('update', $user); Gate::authorize('update', $user);
$user->load('groups'); $user->load('groups');
$organizations = Organization::pluck('name', 'id');
$roles = Role::pluck('name', 'name'); $roles = Role::pluck('name', 'name');
$userGroups = $user->groups->pluck('id')->toArray(); $userGroups = $user->groups->pluck('id')->toArray();
@ -113,7 +111,7 @@ class UserController extends Controller
$allGroups = Group::whereNull('organization_id')->get(); $allGroups = Group::whereNull('organization_id')->get();
} }
return view('admin.users.edit', compact('user', 'organizations', 'roles', 'userGroups', 'allGroups')); return view('admin.users.edit', compact('user', 'roles', 'userGroups', 'allGroups'));
} }
public function update(Request $request, User $user) public function update(Request $request, User $user)

View File

@ -46,12 +46,12 @@
<h5>Настройки</h5> <h5>Настройки</h5>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Организация</label> <label class="form-label">Организация</label>
<select name="organization_id" class="form-select"> <x-searchable-select
<option value="">Без организации</option> name="organization_id"
@foreach($organizations as $id => $name) url="{{ route('api.organizations.search') }}"
<option value="{{ $id }}" {{ old('organization_id') == $id ? 'selected' : '' }}>{{ $name }}</option> placeholder="Начните вводить название организации..."
@endforeach :value="old('organization_id')"
</select> />
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Роль *</label> <label class="form-label">Роль *</label>

View File

@ -45,12 +45,12 @@
<h5>Настройки</h5> <h5>Настройки</h5>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Организация</label> <label class="form-label">Организация</label>
<select name="organization_id" class="form-select"> <x-searchable-select
<option value="">Без организации</option> name="organization_id"
@foreach($organizations as $id => $name) url="{{ route('api.organizations.search') }}"
<option value="{{ $id }}" {{ old('organization_id', $user->organization_id) == $id ? 'selected' : '' }}>{{ $name }}</option> placeholder="Начните вводить название организации..."
@endforeach :value="old('organization_id', $user->organization_id)"
</select> />
</div> </div>
<div class="mb-3"> <div class="mb-3">
<label class="form-label">Роль *</label> <label class="form-label">Роль *</label>