Skip to content

Commit ba87dd1

Browse files
committed
Livewire Table
1 parent 4df9623 commit ba87dd1

File tree

6 files changed

+347
-171
lines changed

6 files changed

+347
-171
lines changed

app/Http/Livewire/UserTable.php

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
namespace App\Http\Livewire;
4+
5+
use App\Http\Livewire;
6+
use Rappasoft\LaravelLivewireTables\DataTableComponent;
7+
use Rappasoft\LaravelLivewireTables\Views\Column;
8+
use App\Models\User;
9+
use App\Models\Link;
10+
11+
class UserTable extends DataTableComponent
12+
{
13+
protected $model = User::class;
14+
15+
public function configure(): void
16+
{
17+
$this->setPrimaryKey('id');
18+
}
19+
20+
public function columns(): array
21+
{
22+
return [
23+
Column::make("Id", "id")
24+
->sortable()
25+
->searchable(),
26+
Column::make("Name", "name")
27+
->sortable()
28+
->searchable(),
29+
Column::make("Email", "email")
30+
->sortable()
31+
->searchable(),
32+
Column::make("Littlelink name", "littlelink_name")
33+
->sortable()
34+
->searchable()
35+
->format(function ($value, $row, Column $column) {
36+
if (!$row->littlelink_name == NULL) {
37+
return "<a href='" . url('') . "/@" . $row->littlelink_name . "' target='_blank' class='text-info'><i class='bi bi-box-arrow-up-right'></i>&nbsp; " . $row->littlelink_name . " </a>";
38+
} else {
39+
return 'N/A';
40+
}
41+
})
42+
->html(),
43+
Column::make("Role", "role")
44+
->sortable()
45+
->searchable(),
46+
Column::make("Test", "id")
47+
->sortable()
48+
->format(function ($value, $row) {
49+
$linkCount = Link::where('user_id', $row->id)->count();
50+
return $linkCount;
51+
}),
52+
Column::make("Clicks Sum", "id")
53+
->sortable()
54+
->format(function ($value, $row) {
55+
$clicksSum = Link::where('user_id', $row->id)->sum('click_number');
56+
return $clicksSum;
57+
}),
58+
Column::make("E-mail", "email_verified_at")
59+
->sortable()
60+
->format(function ($value, $row, Column $column) {
61+
if (env('REGISTER_AUTH') !== 'auth') {
62+
if ($row->role == 'admin' && $row->email_verified_at != '') {
63+
return '<center>-</center>';
64+
} else {
65+
$verifyLink = route('verifyUser', [
66+
'verify' => '-' . $row->email_verified_at,
67+
'id' => $row->id
68+
]);
69+
if ($row->email_verified_at == '') {
70+
return '<a href="' . $verifyLink . '" class="text-danger"><span class="badge bg-danger">' . __('messages.Pending') . '</span></a>';
71+
} else {
72+
return '<a href="' . $verifyLink . '" class="text-danger"><span class="badge bg-success">' . __('messages.Verified') . '</span></a>';
73+
}
74+
}
75+
} else {
76+
return '<center>-</center>';
77+
}
78+
return '';
79+
})->html(),
80+
Column::make("Blocked", "block")
81+
->sortable()
82+
->format(function ($value, $row, Column $column) {
83+
if ($row->role === 'admin' && $row->id === 1) {
84+
return '<center>-</center>';
85+
} else {
86+
$route = route('blockUser', ['block' => $row->block, 'id' => $row->id]);
87+
if ($row->block === 'yes') {
88+
$badge = '<span class="badge bg-danger">'.__('messages.Pending').'</span>';
89+
} elseif ($row->block === 'no') {
90+
$badge = '<span class="badge bg-success">'.__('messages.Approved').'</span>';
91+
}
92+
return "<a href=\"$route\">$badge</a>";
93+
}
94+
})
95+
->html(),
96+
Column::make("Created at", "created_at")
97+
->sortable()
98+
->format(function ($value) {
99+
if ($value) {
100+
return $value->format('d/m/y');
101+
} else {
102+
return '';
103+
}
104+
}),
105+
Column::make("Last seen", "updated_at")
106+
->sortable()
107+
->format(function ($value) {
108+
$now = now();
109+
$diff = $now->diff($value);
110+
111+
if ($diff->d < 1 && $diff->h < 1) {
112+
return 'Now';
113+
} elseif ($diff->d < 1 && $diff->h < 24) {
114+
return $diff->h . ' hours ago';
115+
} elseif ($diff->d < 365) {
116+
return $diff->d . ' days ago';
117+
} else {
118+
return $diff->y . ' years ago';
119+
}
120+
}),
121+
Column::make('Actions', "id")
122+
->format(function ($value, $row, Column $column) {
123+
return view('components.table-components.action', ['user' => $row]);
124+
}),
125+
];
126+
}
127+
}

config/livewire-tables.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
/**
5+
* Options: tailwind | bootstrap-4 | bootstrap-5.
6+
*/
7+
'theme' => 'bootstrap-5',
8+
];

config/livewire.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Class Namespace
8+
|--------------------------------------------------------------------------
9+
|
10+
| This value sets the root namespace for Livewire component classes in
11+
| your application. This value affects component auto-discovery and
12+
| any Livewire file helper commands, like `artisan make:livewire`.
13+
|
14+
| After changing this item, run: `php artisan livewire:discover`.
15+
|
16+
*/
17+
18+
'class_namespace' => 'App\\Http\\Livewire',
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| View Path
23+
|--------------------------------------------------------------------------
24+
|
25+
| This value sets the path for Livewire component views. This affects
26+
| file manipulation helper commands like `artisan make:livewire`.
27+
|
28+
*/
29+
30+
'view_path' => resource_path('views/livewire'),
31+
32+
/*
33+
|--------------------------------------------------------------------------
34+
| Layout
35+
|--------------------------------------------------------------------------
36+
| The default layout view that will be used when rendering a component via
37+
| Route::get('/some-endpoint', SomeComponent::class);. In this case the
38+
| the view returned by SomeComponent will be wrapped in "layouts.app"
39+
|
40+
*/
41+
42+
'layout' => 'layouts.app',
43+
44+
/*
45+
|--------------------------------------------------------------------------
46+
| Livewire Assets URL
47+
|--------------------------------------------------------------------------
48+
|
49+
| This value sets the path to Livewire JavaScript assets, for cases where
50+
| your app's domain root is not the correct path. By default, Livewire
51+
| will load its JavaScript assets from the app's "relative root".
52+
|
53+
| Examples: "/assets", "myurl.com/app".
54+
|
55+
*/
56+
57+
'asset_url' => url(''),
58+
59+
/*
60+
|--------------------------------------------------------------------------
61+
| Livewire App URL
62+
|--------------------------------------------------------------------------
63+
|
64+
| This value should be used if livewire assets are served from CDN.
65+
| Livewire will communicate with an app through this url.
66+
|
67+
| Examples: "https://my-app.com", "myurl.com/app".
68+
|
69+
*/
70+
71+
'app_url' => null,
72+
73+
/*
74+
|--------------------------------------------------------------------------
75+
| Livewire Endpoint Middleware Group
76+
|--------------------------------------------------------------------------
77+
|
78+
| This value sets the middleware group that will be applied to the main
79+
| Livewire "message" endpoint (the endpoint that gets hit everytime
80+
| a Livewire component updates). It is set to "web" by default.
81+
|
82+
*/
83+
84+
'middleware_group' => 'web',
85+
86+
/*
87+
|--------------------------------------------------------------------------
88+
| Livewire Temporary File Uploads Endpoint Configuration
89+
|--------------------------------------------------------------------------
90+
|
91+
| Livewire handles file uploads by storing uploads in a temporary directory
92+
| before the file is validated and stored permanently. All file uploads
93+
| are directed to a global endpoint for temporary storage. The config
94+
| items below are used for customizing the way the endpoint works.
95+
|
96+
*/
97+
98+
'temporary_file_upload' => [
99+
'disk' => null, // Example: 'local', 's3' Default: 'default'
100+
'rules' => null, // Example: ['file', 'mimes:png,jpg'] Default: ['required', 'file', 'max:12288'] (12MB)
101+
'directory' => null, // Example: 'tmp' Default 'livewire-tmp'
102+
'middleware' => null, // Example: 'throttle:5,1' Default: 'throttle:60,1'
103+
'preview_mimes' => [ // Supported file types for temporary pre-signed file URLs.
104+
'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
105+
'mov', 'avi', 'wmv', 'mp3', 'm4a',
106+
'jpg', 'jpeg', 'mpga', 'webp', 'wma',
107+
],
108+
'max_upload_time' => 5, // Max duration (in minutes) before an upload gets invalidated.
109+
],
110+
111+
/*
112+
|--------------------------------------------------------------------------
113+
| Manifest File Path
114+
|--------------------------------------------------------------------------
115+
|
116+
| This value sets the path to the Livewire manifest file.
117+
| The default should work for most cases (which is
118+
| "<app_root>/bootstrap/cache/livewire-components.php"), but for specific
119+
| cases like when hosting on Laravel Vapor, it could be set to a different value.
120+
|
121+
| Example: for Laravel Vapor, it would be "/tmp/storage/bootstrap/cache/livewire-components.php".
122+
|
123+
*/
124+
125+
'manifest_path' => null,
126+
127+
/*
128+
|--------------------------------------------------------------------------
129+
| Back Button Cache
130+
|--------------------------------------------------------------------------
131+
|
132+
| This value determines whether the back button cache will be used on pages
133+
| that contain Livewire. By disabling back button cache, it ensures that
134+
| the back button shows the correct state of components, instead of
135+
| potentially stale, cached data.
136+
|
137+
| Setting it to "false" (default) will disable back button cache.
138+
|
139+
*/
140+
141+
'back_button_cache' => false,
142+
143+
/*
144+
|--------------------------------------------------------------------------
145+
| Render On Redirect
146+
|--------------------------------------------------------------------------
147+
|
148+
| This value determines whether Livewire will render before it's redirected
149+
| or not. Setting it to "false" (default) will mean the render method is
150+
| skipped when redirecting. And "true" will mean the render method is
151+
| run before redirecting. Browsers bfcache can store a potentially
152+
| stale view if render is skipped on redirect.
153+
|
154+
*/
155+
156+
'render_on_redirect' => false,
157+
158+
];
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@if($user->role == 'admin' and $user->id == 1)<center>-</center>
2+
@else
3+
<div class="flex align-items-center list-user-action">
4+
<a class="btn btn-sm btn-icon btn-success" data-bs-toggle="tooltip" data-bs-placement="top" data-original-title="{{__('messages.tt.All links')}}" href="{{ route('showLinksUser', $user->id ) }}" aria-label="All links" data-bs-original-title="All links">
5+
<span class="btn-inner">
6+
<svg class="icon-20" width="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
7+
<circle cx="11.7669" cy="11.7666" r="8.98856" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></circle>
8+
<path d="M18.0186 18.4851L21.5426 22" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
9+
</svg>
10+
</span>
11+
</a>
12+
<a class="btn btn-sm btn-icon btn-warning" data-bs-toggle="tooltip" data-bs-placement="top" data-original-title="{{__('messages.tt.Edit')}}" href="{{ route('editUser', $user->id ) }}" aria-label="Edit" data-bs-original-title="Edit">
13+
<span class="btn-inner">
14+
<svg class="icon-20" width="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
15+
<path d="M11.4925 2.78906H7.75349C4.67849 2.78906 2.75049 4.96606 2.75049 8.04806V16.3621C2.75049 19.4441 4.66949 21.6211 7.75349 21.6211H16.5775C19.6625 21.6211 21.5815 19.4441 21.5815 16.3621V12.3341" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
16+
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.82812 10.921L16.3011 3.44799C17.2321 2.51799 18.7411 2.51799 19.6721 3.44799L20.8891 4.66499C21.8201 5.59599 21.8201 7.10599 20.8891 8.03599L13.3801 15.545C12.9731 15.952 12.4211 16.181 11.8451 16.181H8.09912L8.19312 12.401C8.20712 11.845 8.43412 11.315 8.82812 10.921Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
17+
<path d="M15.1655 4.60254L19.7315 9.16854" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
18+
</svg>
19+
</span>
20+
</a>
21+
<a class="btn btn-sm btn-icon btn-primary" style="@if(!$user->adminUser && Auth::user()->id !== $user->id && $user->block !== 'yes' && ($user->email_verified_at != '' || env('REGISTER_AUTH') == 'auth')) background:#3a57e8;border-color:#3a57e8; @else background:#6c757d;border-color:#6c757d; @endif" data-bs-toggle="tooltip" data-bs-placement="top" data-original-title="{{__('messages.tt.Impersonate')}}" @if(!$user->adminUser && Auth::user()->id !== $user->id && $user->block !== 'yes' && ($user->email_verified_at != '' || env('REGISTER_AUTH') == 'auth')) href="{{ route('authAsID', $user->id ) }}" @endif aria-label="Impersonate" data-bs-original-title="Impersonate">
22+
<span class="btn-inner">
23+
<svg class="icon-20" width="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
24+
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.59151 15.2068C13.2805 15.2068 16.4335 15.7658 16.4335 17.9988C16.4335 20.2318 13.3015 20.8068 9.59151 20.8068C5.90151 20.8068 2.74951 20.2528 2.74951 18.0188C2.74951 15.7848 5.88051 15.2068 9.59151 15.2068Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
25+
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.59157 12.0198C7.16957 12.0198 5.20557 10.0568 5.20557 7.63476C5.20557 5.21276 7.16957 3.24976 9.59157 3.24976C12.0126 3.24976 13.9766 5.21276 13.9766 7.63476C13.9856 10.0478 12.0356 12.0108 9.62257 12.0198H9.59157Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M16.4829 10.8815C18.0839 10.6565 19.3169 9.28253 19.3199 7.61953C19.3199 5.98053 18.1249 4.62053 16.5579 4.36353" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path> <path d="M18.5952 14.7322C20.1462 14.9632 21.2292 15.5072 21.2292 16.6272C21.2292 17.3982 20.7192 17.8982 19.8952 18.2112" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
26+
</svg>
27+
</span>
28+
</a>
29+
<a class="btn btn-sm btn-icon btn-danger confirmation" data-bs-toggle="tooltip" data-bs-placement="top" data-original-title="{{__('messages.tt.Delete')}}" href="{{ route('deleteUser', ['id' => $user->id] ) }}" aria-label="Delete" data-bs-original-title="Delete">
30+
<span class="btn-inner">
31+
<svg class="icon-20" width="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="currentColor">
32+
<path d="M19.3248 9.46826C19.3248 9.46826 18.7818 16.2033 18.4668 19.0403C18.3168 20.3953 17.4798 21.1893 16.1088 21.2143C13.4998 21.2613 10.8878 21.2643 8.27979 21.2093C6.96079 21.1823 6.13779 20.3783 5.99079 19.0473C5.67379 16.1853 5.13379 9.46826 5.13379 9.46826" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
33+
<path d="M20.708 6.23975H3.75" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
34+
<path d="M17.4406 6.23973C16.6556 6.23973 15.9796 5.68473 15.8256 4.91573L15.5826 3.69973C15.4326 3.13873 14.9246 2.75073 14.3456 2.75073H10.1126C9.53358 2.75073 9.02558 3.13873 8.87558 3.69973L8.63258 4.91573C8.47858 5.68473 7.80258 6.23973 7.01758 6.23973" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
35+
</svg>
36+
</span>
37+
</a>
38+
</div>
39+
@endif

resources/views/layouts/sidebar.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<base href="{{url()->current()}}" />
2121

22+
@livewireStyles
2223
@include('layouts.analytics')
2324
@stack('sidebar-stylesheets')
2425
@include('layouts.notifications')
@@ -791,7 +792,7 @@
791792
<script src="{{ asset('assets/js/jquery-block-ui.js') }}"></script>
792793
<script src="{{ asset('assets/js/main-dashboard.js') }}"></script>
793794

794-
795+
@livewireScripts
795796
@stack('sidebar-scripts')
796797

797798
</body>

0 commit comments

Comments
 (0)