Skip to content

Commit c1c0ad2

Browse files
authored
Merge pull request #50 from laravelcm/users-admin-table
Users admin table
2 parents f544e59 + 3c6ef79 commit c1c0ad2

File tree

9 files changed

+113
-6
lines changed

9 files changed

+113
-6
lines changed

app/Http/Controllers/Cpanel/DashboardController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class DashboardController extends Controller
1111
{
12-
public function home()
12+
public function __invoke()
1313
{
1414
$users = Cache::remember('new-members', now()->addHour(), fn () => User::verifiedUsers()->latest()->limit(15)->get());
1515
$latestArticles = Cache::remember('last-posts', now()->addHour(), fn () => Article::latest()->limit(2)->get());
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Cpanel;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Models\User;
7+
8+
class UserController extends Controller
9+
{
10+
public function __invoke()
11+
{
12+
return view('cpanel.users.index', [
13+
'users' => User::verifiedUsers()->latest()->paginate(15),
14+
]);
15+
}
16+
}

app/Models/User.php

Lines changed: 14 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,19 @@ 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+
99113
public function isAdmin(): bool
100114
{
101115
return $this->hasRole('admin');

app/Widgets/RecentNumbers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function run()
7777
'count' => $totalViews,
7878
'increase' => $difference > 0,
7979
'decreased' => $difference < 0,
80-
'current' => $differenceViews,
80+
'current' => max($differenceViews, 0),
8181
],
8282
]);
8383
}

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"/js/app.js": "/js/app.js?id=3bd7a17ae8879cea08888521628605ff",
3-
"/css/app.css": "/css/app.css?id=98fe644f6b48d5830bf4c4551fd7f65e"
3+
"/css/app.css": "/css/app.css?id=d4494514b4272e25cc1fd3f9575bdb47"
44
}

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: 5 additions & 1 deletion
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');
7-
Route::get('/home', [DashboardController::class, 'home'])->name('home');
8+
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)