Skip to content

Commit 4d5147e

Browse files
committed
✨ ajout de la page de listing desutilisateurs
1 parent c7e623f commit 4d5147e

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Cpanel;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\User;
7+
use Illuminate\Http\Request;
8+
9+
class UserController extends Controller
10+
{
11+
public function __invoke()
12+
{
13+
return view('cpanel.users.index', [
14+
'users' => User::verifiedUsers()->latest()->paginate(15),
15+
]);
16+
}
17+
}

app/Models/User.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia
8383
*/
8484
protected $appends = [
8585
'profile_photo_url',
86+
'roles_label',
8687
];
8788

8889
public function hasProvider($provider): bool
@@ -96,6 +97,20 @@ public function hasProvider($provider): bool
9697
return false;
9798
}
9899

100+
public function getRolesLabelAttribute(): string
101+
{
102+
$roles = $this->getRoleNames()->toArray();
103+
104+
if (count($roles)) {
105+
return implode(', ', array_map(function ($item) {
106+
return ucwords($item);
107+
}, $roles));
108+
}
109+
110+
return 'N/A';
111+
}
112+
113+
99114
public function isAdmin(): bool
100115
{
101116
return $this->hasRole('admin');

resources/views/components/layouts/admin-menu.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="{{ route('cpanel.home') }}" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['cpanel.home'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}" aria-current="page" x-state:on="Current" x-state:off="Default">
66
{{ __('Tableau de bord') }}
77
</a>
8-
<a href="#" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['users*'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}">
8+
<a href="{{ route('cpanel.users.browse') }}" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['cpanel.users*'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}">
99
{{ __('Utilisateurs') }}
1010
</a>
1111
<a href="#" class="text-sm font-medium rounded-md py-2 px-3 inline-flex items-center {{ active(['categories*'], 'bg-green-50 text-green-800', 'text-skin-base hover:bg-skin-card-muted hover:text-skin-inverted') }}">
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<x-layouts.cp title="Tableau de bord">
2+
<x-container class="max-w-7xl mx-auto px-4 sm:px-6">
3+
<div>
4+
<div class="sm:flex sm:items-center">
5+
<div class="sm:flex-auto">
6+
<h1 class="text-xl font-semibold text-skin-inverted">{{ __('Utilisateurs') }}</h1>
7+
<p class="mt-2 text-sm text-skin-inverted-muted">{{ __('Une liste de tous les utilisateurs de votre compte, avec leur nom, leur titre, leur email et leur rôle.') }}</p>
8+
</div>
9+
<div class="mt-4 sm:mt-0 sm:ml-16 sm:flex-none">
10+
<x-button type="button">{{ __('Inviter') }}</x-button>
11+
</div>
12+
</div>
13+
<div class="mt-8 flex flex-col">
14+
<div class="-my-2 -mx-4 overflow-x-auto sm:-mx-6 lg:-mx-8">
15+
<div class="inline-block min-w-full py-2 align-middle md:px-6 lg:px-8">
16+
<div class="overflow-hidden shadow ring-1 ring-black ring-opacity-5 md:rounded-lg">
17+
<table class="min-w-full divide-y divide-skin-base">
18+
<thead class="bg-skin-card-muted">
19+
<tr>
20+
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-skin-inverted sm:pl-6">{{ __('Nom') }}</th>
21+
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-skin-inverted">{{ __('Email') }}</th>
22+
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-skin-inverted">{{ __('Role') }}</th>
23+
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-skin-inverted">{{ __('Inscription') }}</th>
24+
<th scope="col" class="relative py-3.5 pl-3 pr-4 sm:pr-6">
25+
<span class="sr-only">{{ __('Éditer') }}</span>
26+
</th>
27+
</tr>
28+
</thead>
29+
<tbody class="divide-y divide-skin-input bg-skin-menu">
30+
@foreach($users as $user)
31+
<tr>
32+
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-skin-inverted sm:pl-6">
33+
<div class="flex items-center">
34+
<div class="h-10 w-10 flex-shrink-0">
35+
<img class="h-10 w-10 rounded-full" src="{{ $user->profile_photo_url }}" alt="{{ $user->username }}">
36+
</div>
37+
<div class="ml-4">
38+
<div class="flex items-center font-medium text-skin-inverted">
39+
{{ $user->name }}
40+
@if($user->isLoggedInUser())
41+
<span class="ml-2 inline-flex items-center px-1.5 py-0.5 rounded-full text-xs font-medium leading-none bg-green-50 text-green-800">
42+
{{ __('Moi') }}
43+
</span>
44+
@endif
45+
</div>
46+
<div class="text-skin-base">{{ $user->username }}</div>
47+
</div>
48+
</div>
49+
</td>
50+
<td class="whitespace-nowrap px-3 py-4 text-sm text-skin-base">{{ $user->email }}</td>
51+
<td class="whitespace-nowrap px-3 py-4 text-sm text-skin-base">{{ $user->roles_label }}</td>
52+
<td class="whitespace-nowrap px-3 py-4 text-sm text-skin-base">{{ $user->created_at->diffForHumans() }}</td>
53+
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6">
54+
@if(! $user->isLoggedInUser())
55+
<a href="#" class="text-green-600 hover:text-green-900">{{ __('Afficher') }}<span class="sr-only">, {{ $user->name }}</span></a>
56+
@endif
57+
</td>
58+
</tr>
59+
@endforeach
60+
</tbody>
61+
</table>
62+
</div>
63+
</div>
64+
</div>
65+
</div>
66+
67+
<div class="mt-6">
68+
{{ $users->links() }}
69+
</div>
70+
</div>
71+
72+
</x-container>
73+
</x-layouts.cp>

routes/cpanel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22

33
use App\Http\Controllers\Cpanel\DashboardController;
4+
use App\Http\Controllers\Cpanel\UserController;
45
use Illuminate\Support\Facades\Route;
56

67
Route::redirect('/', 'cpanel/home');
78
Route::get('/home', DashboardController::class)->name('home');
9+
Route::prefix('users')->as('users.')->group(function () {
10+
Route::get('/', UserController::class)->name('browse');
11+
});

0 commit comments

Comments
 (0)