170 lines
7.6 KiB
PHP
170 lines
7.6 KiB
PHP
@extends('layouts.app')
|
|
|
|
@section('content')
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">User Management</h3>
|
|
<div class="card-tools">
|
|
<a href="{{ route('user-management.create') }}" class="btn btn-primary">
|
|
<i class="fas fa-plus"></i> Add New User
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
@include('components.alerts')
|
|
|
|
<div class="mb-3">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" id="searchInput" placeholder="Search users...">
|
|
<div class="input-group-append">
|
|
<button class="btn btn-outline-secondary" type="button">
|
|
<i class="fas fa-search"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<select class="form-control" id="roleFilter">
|
|
<option value="">All Roles</option>
|
|
@foreach($roles as $role)
|
|
<option value="{{ $role }}">{{ ucfirst($role) }}</option>
|
|
@endforeach
|
|
</select>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<select class="form-control" id="statusFilter">
|
|
<option value="">All Status</option>
|
|
<option value="1">Active</option>
|
|
<option value="0">Inactive</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-striped" id="usersTable">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Username</th>
|
|
<th>Email</th>
|
|
<th>Role</th>
|
|
<th>Status</th>
|
|
<th>Created At</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($users as $user)
|
|
<tr>
|
|
<td>{{ $user['id'] }}</td>
|
|
<td>{{ $user['username'] }}</td>
|
|
<td>{{ $user['email'] }}</td>
|
|
<td>
|
|
<span class="badge badge-info">
|
|
{{ ucfirst($user['role']) }}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<span class="badge badge-{{ $user['is_active'] ? 'success' : 'danger' }}">
|
|
{{ $user['is_active'] ? 'Active' : 'Inactive' }}
|
|
</span>
|
|
</td>
|
|
<td>{{ \Carbon\Carbon::parse($user['created_at'])->format('Y-m-d H:i') }}</td>
|
|
<td>
|
|
<div class="btn-group">
|
|
<a href="{{ route('user-management.edit', $user['id']) }}"
|
|
class="btn btn-sm btn-info"
|
|
data-toggle="tooltip"
|
|
title="Edit User">
|
|
<i class="fas fa-edit"></i>
|
|
</a>
|
|
<form action="{{ route('user-management.destroy', $user['id']) }}"
|
|
method="POST"
|
|
class="d-inline delete-form">
|
|
@csrf
|
|
@method('DELETE')
|
|
<button type="submit"
|
|
class="btn btn-sm btn-danger"
|
|
data-toggle="tooltip"
|
|
title="Delete User">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="7" class="text-center">No users found</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="mt-3">
|
|
{{ $users->links() }}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('styles')
|
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/dataTables.bootstrap4.min.css">
|
|
@endpush
|
|
|
|
@push('scripts')
|
|
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
|
|
<script src="https://cdn.datatables.net/1.10.24/js/dataTables.bootstrap4.min.js"></script>
|
|
<script>
|
|
$(document).ready(function() {
|
|
// Initialize DataTable
|
|
const table = $('#usersTable').DataTable({
|
|
"responsive": true,
|
|
"processing": true,
|
|
"serverSide": true,
|
|
"ajax": "{{ route('user-management.data') }}",
|
|
"order": [[0, "desc"]],
|
|
"columns": [
|
|
{ "data": "id" },
|
|
{ "data": "username" },
|
|
{ "data": "email" },
|
|
{ "data": "role" },
|
|
{ "data": "status" },
|
|
{ "data": "created_at" },
|
|
{ "data": "actions", "orderable": false }
|
|
]
|
|
});
|
|
|
|
// Apply filters
|
|
$('#roleFilter, #statusFilter').change(function() {
|
|
table.ajax.reload();
|
|
});
|
|
|
|
// Search functionality
|
|
$('#searchInput').keyup(function() {
|
|
table.search($(this).val()).draw();
|
|
});
|
|
|
|
// Delete confirmation
|
|
$('.delete-form').on('submit', function(e) {
|
|
e.preventDefault();
|
|
if (confirm('Are you sure you want to delete this user?')) {
|
|
this.submit();
|
|
}
|
|
});
|
|
|
|
// Initialize tooltips
|
|
$('[data-toggle="tooltip"]').tooltip();
|
|
});
|
|
</script>
|
|
@endpush
|