tambah relation user-role

This commit is contained in:
Saufi
2026-05-11 14:13:25 +08:00
parent dc48e38ba6
commit e404aee576
12 changed files with 256 additions and 11 deletions

View File

@@ -5,6 +5,7 @@
<th class="px-6 py-3">{{ __('Name') }}</th>
<th class="px-6 py-3">{{ __('Email') }}</th>
<th class="px-6 py-3">{{ __('Joined') }}</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody>
@@ -14,12 +15,17 @@
<td class="px-6 py-4 font-medium">{{ $user->name }}</td>
<td class="px-6 py-4">{{ $user->email }}</td>
<td class="px-6 py-4">{{ $user->created_at->format('d M Y') }}</td>
<td class="px-6 py-4 text-right">
<a href="{{ route('users.edit', $user) }}" class="text-indigo-600 dark:text-indigo-400 hover:underline text-sm font-medium">
{{ __('Edit') }}
</a>
</td>
</tr>
@endforeach
@if ($users->isEmpty())
<tr>
<td colspan="4" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
<td colspan="5" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
{{ __('No users found.') }}
</td>
</tr>

View File

@@ -0,0 +1,65 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
{{ __('Edit User') }}: {{ $user->name }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
<div class="max-w-xl">
<section>
<header>
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
{{ __('Assign Roles') }}
</h2>
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
{{ __('Select the roles to assign to this user.') }}
</p>
</header>
<form method="post" action="{{ route('users.update', $user) }}" class="mt-6 space-y-6">
@csrf
@method('put')
<div class="space-y-3">
@forelse ($roles as $role)
<label class="flex items-start gap-3 cursor-pointer">
<input
type="checkbox"
name="roles[]"
value="{{ $role->id }}"
{{ $user->roles->contains($role) ? 'checked' : '' }}
class="mt-0.5 rounded border-gray-300 dark:border-gray-700 text-indigo-600 shadow-sm focus:ring-indigo-500 dark:focus:ring-indigo-600 dark:bg-gray-900"
/>
<div>
<span class="text-sm font-medium text-gray-900 dark:text-gray-100">{{ $role->name }}</span>
@if ($role->description)
<p class="text-xs text-gray-500 dark:text-gray-400">{{ $role->description }}</p>
@endif
</div>
</label>
@empty
<p class="text-sm text-gray-500 dark:text-gray-400">{{ __('No roles available. Create one first.') }}</p>
@endforelse
</div>
<x-input-error class="mt-2" :messages="$errors->get('roles')" />
<x-input-error class="mt-2" :messages="$errors->get('roles.*')" />
<div class="flex items-center gap-4">
<x-primary-button>{{ __('Save Roles') }}</x-primary-button>
<a href="{{ route('users.index') }}" class="text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 underline">
{{ __('Cancel') }}
</a>
</div>
</form>
</section>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -21,9 +21,10 @@
this.loading = false;
}
}"
@click.prevent="
@click="
const link = $event.target.closest('a[href]');
if (link && $refs.tableContainer.contains(link)) {
if (link && link.closest('nav[role=navigation]') && $refs.tableContainer.contains(link)) {
$event.preventDefault();
paginate(link.href);
}
"