@extends('layouts.app')
@section('title',$user->exists?'Edit User':'New User') @section('page_title',$user->exists?'Edit User':'New User')
@section('content')<div class="page-header"><div><h1>{{ $user->exists?'Edit User':'Create User' }}</h1><p class="muted">Assign one or more roles and optionally restrict the user to a branch.</p></div><a class="btn btn-secondary" href="{{ route('users.index') }}">Back</a></div>
<div class="card"><div class="card-body"><form method="post" action="{{ $user->exists?route('users.update',$user):route('users.store') }}">@csrf @if($user->exists)@method('put')@endif
<div class="form-grid"><div class="field"><label>Name *</label><input class="control" name="name" value="{{ old('name',$user->name) }}" required></div><div class="field"><label>Email *</label><input class="control" type="email" name="email" value="{{ old('email',$user->email) }}" required></div><div class="field"><label>Branch Restriction</label><select class="control" name="branch_id"><option value="">All branches</option>@foreach($branches as $branch)<option value="{{ $branch->id }}" @selected((string)old('branch_id',$user->branch_id)===(string)$branch->id)>{{ $branch->code }} - {{ $branch->name }}</option>@endforeach</select></div><div class="field"><label>Status</label><label class="checkbox"><input type="checkbox" name="is_active" value="1" @checked(old('is_active',$user->exists?$user->is_active:true))> Active user</label></div><div class="field"><label>{{ $user->exists?'New Password (leave blank to keep)':'Password *' }}</label><input class="control" type="password" name="password" {{ $user->exists?'':'required' }} minlength="10"></div><div class="field"><label>Confirm Password</label><input class="control" type="password" name="password_confirmation" {{ $user->exists?'':'required' }} minlength="10"></div><div class="field span-2"><label>Roles *</label><div class="choice-grid">@foreach($roles as $role)<label class="choice"><input type="checkbox" name="role_ids[]" value="{{ $role->id }}" @checked(in_array($role->id,old('role_ids',$user->exists?$user->roles->pluck('id')->all():[])))><span><strong>{{ $role->name }}</strong><small>{{ $role->slug }}</small></span></label>@endforeach</div></div></div><div class="form-actions"><button class="btn btn-primary">Save User</button>@if($user->exists && !$user->is(auth()->user()) && auth()->user()->hasPermission('users.delete_draft'))<button type="submit" form="delete-user" class="btn btn-danger" onclick="return confirm('Delete this user?')">Delete</button>@endif</div></form>@if($user->exists)<form id="delete-user" method="post" action="{{ route('users.destroy',$user) }}">@csrf @method('delete')</form>@endif</div></div>@endsection
