user list
This commit is contained in:
8
.claude/settings.local.json
Normal file
8
.claude/settings.local.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(php artisan *)",
|
||||
"Bash(vendor/bin/pint --dirty --format agent)"
|
||||
]
|
||||
}
|
||||
}
|
||||
15
app/Http/Controllers/UserController.php
Normal file
15
app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$users = User::orderBy('name')->get();
|
||||
|
||||
return view('users.index', compact('users'));
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@
|
||||
<x-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
|
||||
{{ __('Dashboard') }}
|
||||
</x-nav-link>
|
||||
<x-nav-link :href="route('users.index')" :active="request()->routeIs('users.index')">
|
||||
{{ __('Users') }}
|
||||
</x-nav-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -70,6 +73,9 @@
|
||||
<x-responsive-nav-link :href="route('dashboard')" :active="request()->routeIs('dashboard')">
|
||||
{{ __('Dashboard') }}
|
||||
</x-responsive-nav-link>
|
||||
<x-responsive-nav-link :href="route('users.index')" :active="request()->routeIs('users.index')">
|
||||
{{ __('Users') }}
|
||||
</x-responsive-nav-link>
|
||||
</div>
|
||||
|
||||
<!-- Responsive Settings Options -->
|
||||
|
||||
44
resources/views/users/index.blade.php
Normal file
44
resources/views/users/index.blade.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<x-app-layout>
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
|
||||
{{ __('Users') }}
|
||||
</h2>
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="bg-white dark:bg-gray-800 overflow-hidden shadow-sm sm:rounded-lg">
|
||||
<div class="p-6">
|
||||
<table class="w-full text-sm text-left text-gray-900 dark:text-gray-100">
|
||||
<thead class="text-xs text-gray-700 dark:text-gray-400 uppercase bg-gray-50 dark:bg-gray-700">
|
||||
<tr>
|
||||
<th class="px-6 py-3">#</th>
|
||||
<th class="px-6 py-3">{{ __('Name') }}</th>
|
||||
<th class="px-6 py-3">{{ __('Email') }}</th>
|
||||
<th class="px-6 py-3">{{ __('Joined') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($users as $index => $user)
|
||||
<tr class="{{ $index % 2 === 0 ? 'bg-white dark:bg-gray-800' : 'bg-gray-50 dark:bg-gray-700' }} border-b border-gray-200 dark:border-gray-600">
|
||||
<td class="px-6 py-4">{{ $index + 1 }}</td>
|
||||
<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>
|
||||
</tr>
|
||||
@endforeach
|
||||
|
||||
@if ($users->isEmpty())
|
||||
<tr>
|
||||
<td colspan="4" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
|
||||
{{ __('No users found.') }}
|
||||
</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-app-layout>
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\UserController;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/', function () {
|
||||
@@ -12,6 +13,7 @@ Route::get('/dashboard', function () {
|
||||
})->middleware(['auth', 'verified'])->name('dashboard');
|
||||
|
||||
Route::middleware('auth')->group(function () {
|
||||
Route::get('/users', [UserController::class, 'index'])->name('users.index');
|
||||
Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
|
||||
Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
|
||||
Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
||||
|
||||
25
tests/Feature/UserIndexTest.php
Normal file
25
tests/Feature/UserIndexTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
test('guests are redirected to login from users page', function () {
|
||||
$this->get('/users')->assertRedirect('/login');
|
||||
});
|
||||
|
||||
test('authenticated users can view the users page', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)
|
||||
->get('/users')
|
||||
->assertOk()
|
||||
->assertViewIs('users.index');
|
||||
});
|
||||
|
||||
test('users page lists all users', function () {
|
||||
$users = User::factory()->count(3)->create();
|
||||
|
||||
$this->actingAs($users->first())
|
||||
->get('/users')
|
||||
->assertOk()
|
||||
->assertViewHas('users', fn ($viewUsers) => $viewUsers->count() === User::count());
|
||||
});
|
||||
Reference in New Issue
Block a user