> For the complete documentation index, see [llms.txt](https://alvan.kitakale.id/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alvan.kitakale.id/buku-induk/halaman-user/halaman-list-user.md).

# Halaman List User

Buat file baru dengan nama `index.blade.php` di dalam `resources/views/users/` . Lalu pastekan ke dalam file tersebut dengan menggunakan file source code di bawah ini:

```php
@extends('layouts.app')

@section('content')
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <div>
        <h1 class="h3 mb-1 text-gray-800">Manajemen Pengguna</h1>
        <p class="text-muted mb-0">Kelola akun dan hak akses pengguna.</p>
    </div>
    <a class="btn btn-primary btn-sm mt-3 mt-sm-0" href="{{ route('users.create') }}">
        <i class="fas fa-user-plus mr-1"></i> Tambah Pengguna
    </a>
</div>

@if (session('success'))
    <div class="alert alert-success alert-dismissible fade show" role="alert">
        {{ session('success') }}
        <button type="button" class="close" data-dismiss="alert" aria-label="Tutup">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
@endif

@if (session('error'))
    <div class="alert alert-danger alert-dismissible fade show" role="alert">
        {{ session('error') }}
        <button type="button" class="close" data-dismiss="alert" aria-label="Tutup">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
@endif

<div class="card shadow mb-4">
    <div class="card-header py-3 d-flex flex-column flex-md-row align-items-md-center justify-content-between">
        <h6 class="m-0 font-weight-bold text-primary">Daftar Pengguna</h6>
        <form class="form-inline mt-3 mt-md-0" action="{{ route('users.index') }}" method="GET">
            <label class="sr-only" for="user-search">Cari nama atau email</label>
            <input class="form-control form-control-sm" id="user-search" name="search" type="search"
                value="{{ $search }}" placeholder="Cari nama atau email">
            <button class="btn btn-primary btn-sm ml-2" type="submit" aria-label="Cari pengguna" title="Cari">
                <i class="fas fa-search"></i>
            </button>
            @if ($search !== '')
                <a class="btn btn-light btn-sm ml-2" href="{{ route('users.index') }}">Reset</a>
            @endif
        </form>
    </div>

    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover mb-0">
                <thead class="thead-light">
                    <tr>
                        <th scope="col">ID</th>
                        <th scope="col">Nama</th>
                        <th scope="col">Email</th>
                        <th scope="col">Role</th>
                        <th scope="col">Terdaftar</th>
                        <th scope="col" class="text-center">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($users as $user)
                        <tr>
                            <td>{{ $user->id }}</td>
                            <td>{{ $user->name }}</td>
                            <td>{{ $user->email }}</td>
                            <td><span class="badge badge-info">{{ ucfirst($user->role ?? 'siswa') }}</span></td>
                            <td>{{ $user->created_at?->format('d/m/Y H:i') ?? '-' }}</td>
                            <td class="text-center text-nowrap">
                                <a class="btn btn-outline-primary btn-sm" href="{{ route('users.edit', $user) }}"
                                    aria-label="Edit {{ $user->name }}" title="Edit">
                                    <i class="fas fa-edit"></i>
                                </a>
                                @if (auth()->id() !== $user->id)
                                    <form class="d-inline" action="{{ route('users.destroy', $user) }}" method="POST"
                                        onsubmit="return confirm('Yakin ingin menghapus pengguna ini?')">
                                        @csrf
                                        @method('DELETE')
                                        <button class="btn btn-outline-danger btn-sm" type="submit"
                                            aria-label="Hapus {{ $user->name }}" title="Hapus">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </form>
                                @else
                                    <span class="badge badge-light">Akun Anda</span>
                                @endif
                            </td>
                        </tr>
                    @empty
                        <tr>
                            <td class="text-center text-muted py-4" colspan="6">
                                @if ($search !== '')
                                    Tidak ada pengguna yang cocok dengan pencarian.
                                @else
                                    Belum ada pengguna.
                                @endif
                            </td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>

        <div class="d-flex flex-column flex-md-row align-items-md-center justify-content-between mt-3">
            <p class="text-muted small mb-2 mb-md-0">
                Menampilkan {{ $users->firstItem() ?? 0 }}-{{ $users->lastItem() ?? 0 }} dari {{ $users->total() }} pengguna
            </p>
            {{ $users->links('pagination::bootstrap-4') }}
        </div>
    </div>
</div>
@endsection
```
