Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 9aab81c

Browse files
committed
update datatables and docs
1 parent d6ecb6b commit 9aab81c

File tree

11 files changed

+124
-161
lines changed

11 files changed

+124
-161
lines changed

README.md

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -24,81 +24,18 @@ an ui to link users to roles and assign permissions to roles.
2424
## Installation
2525

2626

27-
## Installing Laravel Jetstream ( if you didn't already install it )
27+
## Installing Laravel Jetstream, the Livewire version
2828

29-
```php
30-
composer require laravel/jetstream
31-
32-
php artisan jetstream:install livewire
33-
```
29+
Laravel Jetstream is a requirement for this package, if you haven't allready install it i refer
30+
to the docs of Jetstream to install it.
3431

35-
After this you have to install and build the assets
32+
https://jetstream.laravel.com/2.x/installation.html#livewire
3633

37-
```shell
38-
npm install
39-
npm run dev
40-
```
41-
42-
## Installing Laravel Permissions ( if you didn't already install it )
43-
44-
if you hadn't already installed Laravel Permissions , install it first
45-
46-
```shell
47-
composer require spatie/laravel-permission
48-
```
49-
After the installation you should first publish the config file and migrations.
50-
51-
php artisan vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
52-
53-
54-
First, add the Spatie\Permission\Traits\HasRoles trait to your User model(s):
55-
56-
```php
57-
use Illuminate\Foundation\Auth\User as Authenticatable;
58-
use Spatie\Permission\Traits\HasRoles;
59-
60-
class User extends Authenticatable
61-
{
62-
use HasRoles;
63-
64-
// ...
65-
}
66-
```
34+
## Installing Laravel Permissions
6735

68-
## Installing Laravel Livewire datatables
69-
70-
Inforce uses datatables for its overviews. Because the datatables i use don't include a tailwind ui i've created a fork. The fork is in pull request but while it's still open you have to include my
71-
version as a root dependencie in your project. In future versions this installation step will be obsolete.
72-
73-
add this to your composer.json
74-
75-
```shell
76-
"repositories": [
77-
{
78-
"type": "vcs",
79-
"url": "https://github.com/LLoadout/laravel-livewire-tables"
80-
}
81-
],
82-
```
83-
84-
add this in your required packages
85-
86-
```shell
87-
"rappasoft/laravel-livewire-tables": "dev-tailwind as 0.3.3"
88-
```
89-
90-
now you can execute an update
91-
92-
```shell
93-
composer update
94-
```
95-
96-
publish the config file
97-
```shell
98-
php artisan vendor:publish --provider="Rappasoft\LaravelLivewireTables\LaravelLivewireTablesServiceProvider" --tag=config
99-
```
36+
If you hadn't already installed Laravel Permissions , install it first, therefor I refer to the docs of Spatie
10037

101-
then change "theme" to "tailwind" in /config/laravel-livewire-tables.php
38+
https://spatie.be/docs/laravel-permission/v4/installation-laravel
10239

10340
## Installation of LLoadout inforce
10441

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"require": {
1313
"php": "^7.4|^8.0",
1414
"livewire/livewire": "^2.0",
15-
"spatie/laravel-package-tools": "^1.1"
15+
"spatie/laravel-package-tools": "^1.1",
16+
"rappasoft/laravel-livewire-tables" : "^1.2"
17+
1618
},
1719
"autoload": {
1820
"psr-4": {

resources/views/access-ui/access.blade.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<x-slot name="header">
2-
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3-
{{ __('Access') }}
4-
</h2>
5-
</x-slot>
1+
<div class="py-3">
2+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 py-3">
3+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
4+
{{ __('Permissions') }}
5+
</h2>
6+
</div>
7+
68

7-
<div class="py-12">
89
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
910
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
1011
<div class="container mx-auto">

resources/views/menu-ui/menus.blade.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
<x-slot name="header">
2-
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3-
{{ __('Menus') }}
4-
</h2>
5-
</x-slot>
1+
<div class="py-3">
2+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 py-3">
3+
<div class="grid grid-cols-2">
4+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
5+
{{ __('Menus') }}
6+
</h2>
7+
<div>
8+
<a href="{{ route('menu') }}" class="float-right bg-blue-500 text-white font-bold uppercase text-xs px-4 py-2 rounded shadow hover:shadow-md outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150" type="button">
9+
+ New
10+
</a>
11+
</div>
12+
</div>
13+
</div>
614

7-
<div class="py-12">
815
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
9-
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
16+
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg p-2">
1017
<livewire:menus-table/>
1118
</div>
1219
</div>
1320
</div>
14-

resources/views/permission-ui/permissions.blade.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
<x-slot name="header">
2-
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3-
{{ __('Permissions') }}
4-
</h2>
5-
</x-slot>
1+
<div class="py-3">
2+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 py-3">
3+
<div class="grid grid-cols-2">
4+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
5+
{{ __('Permissions') }}
6+
</h2>
7+
<div>
8+
<a href="{{ route('permission') }}" class="float-right bg-blue-500 text-white font-bold uppercase text-xs px-4 py-2 rounded shadow hover:shadow-md outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150" type="button">
9+
+ New
10+
</a>
11+
</div>
12+
</div>
13+
</div>
14+
615

7-
<div class="py-12">
816
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
9-
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
17+
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg p-2">
1018
<livewire:permissions-table/>
1119
</div>
1220
</div>

resources/views/user-ui/roles.blade.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
<x-slot name="header">
2-
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3-
{{ __('Roles') }}
4-
</h2>
5-
</x-slot>
1+
<div class="py-3">
2+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 py-3">
3+
<div class="grid grid-cols-2">
4+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
5+
{{ __('Roles') }}
6+
</h2>
7+
<div>
8+
<a href="{{ route('role.edit') }}" class="float-right bg-blue-500 text-white font-bold uppercase text-xs px-4 py-2 rounded shadow hover:shadow-md outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150" type="button">
9+
+ New
10+
</a>
11+
</div>
12+
</div>
13+
</div>
614

7-
<div class="py-12">
815
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
9-
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
16+
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg p-2">
1017
<livewire:roles-table/>
1118
</div>
1219
</div>
Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
<x-slot name="header">
2-
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
3-
{{ __('Users') }}
4-
</h2>
5-
</x-slot>
1+
<div class="py-3">
2+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 py-3">
3+
<div class="grid grid-cols-2">
4+
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
5+
{{ __('Users') }}
6+
</h2>
7+
<div>
8+
<a href="{{ route('users.edit') }}" class="float-right bg-blue-500 text-white font-bold uppercase text-xs px-4 py-2 rounded shadow hover:shadow-md outline-none focus:outline-none mr-1 mb-1 ease-linear transition-all duration-150" type="button">
9+
+ New
10+
</a>
11+
</div>
12+
</div>
13+
</div>
614

7-
<div class="py-12">
815
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
9-
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
16+
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg p-2">
1017
<livewire:users-table/>
1118
</div>
1219
</div>
13-
</div>
20+
21+
</div>

src/Http/Livewire/MenusTable.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,37 @@
55
use App\User;
66
use Illuminate\Database\Eloquent\Builder;
77
use LLoadoutInforce\Models\Menu;
8-
use Rappasoft\LaravelLivewireTables\TableComponent;
9-
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
8+
use Rappasoft\LaravelLivewireTables\DataTableComponent;
109
use Rappasoft\LaravelLivewireTables\Views\Column;
1110

12-
class MenusTable extends TableComponent
11+
class MenusTable extends DataTableComponent
1312
{
14-
use HtmlComponents;
15-
16-
public $addRoute = "menu";
17-
public $clearSearchButton = true;
1813

1914
public function query(): Builder
2015
{
21-
return Menu::query();
16+
return Menu::query()
17+
->when($this->getFilter('search'), fn ($query, $term) => $query->where('name', 'like', '%'.$term.'%')->orWhere('route', 'like', '%'.$term.'%'));
18+
2219
}
2320

2421
public function columns(): array
2522
{
2623

2724
return [
2825
Column::make('ID', 'id')
29-
->searchable()
30-
->sortable()
31-
->format(function (Menu $model) {
32-
return $this->linkRoute('menu', $model->id, $model->id);
33-
}),
26+
->sortable(),
3427
Column::make('Name', 'name')
35-
->searchable()
3628
->sortable(),
3729
Column::make('Route', 'route')
38-
->searchable()
3930
->sortable(),
4031
];
4132

4233
}
34+
35+
public function getTableRowUrl($row): string
36+
{
37+
return route('menu', $row);
38+
}
39+
40+
4341
}

src/Http/Livewire/PermissionsTable.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,35 @@
66
use Spatie\Permission\Models\Permission;
77
use Illuminate\Database\Eloquent\Builder;
88
use Rappasoft\LaravelLivewireTables\Views\Column;
9-
use Rappasoft\LaravelLivewireTables\TableComponent;
10-
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
9+
use Rappasoft\LaravelLivewireTables\DataTableComponent;
1110

12-
class PermissionsTable extends TableComponent
11+
class PermissionsTable extends DataTableComponent
1312
{
14-
use HtmlComponents;
1513

1614
public $addRoute = "permission";
17-
public $clearSearchButton = true;
15+
1816

1917
public function query(): Builder
2018
{
21-
return Permission::query();
19+
return Permission::query()
20+
->when($this->getFilter('search'), fn ($query, $term) => $query->where('name', 'like', '%'.$term.'%'));
2221
}
2322

2423
public function columns(): array
2524
{
2625

2726
return [
2827
Column::make('ID', 'id')
29-
->searchable()
30-
->sortable()
31-
->format(function (Permission $model) {
32-
return $this->linkRoute('permission', $model->id, $model->id);
33-
}),
28+
->sortable(),
3429
Column::make('Name', 'name')
35-
->searchable()
3630
->sortable(),
3731
];
3832

3933
}
34+
35+
public function getTableRowUrl($row): string
36+
{
37+
return route('permission', $row);
38+
}
39+
4040
}

src/Http/Livewire/RolesTable.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,34 @@
44

55
use App\User;
66
use Illuminate\Database\Eloquent\Builder;
7-
use Rappasoft\LaravelLivewireTables\TableComponent;
7+
use Rappasoft\LaravelLivewireTables\DataTableComponent;
88
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
99
use Rappasoft\LaravelLivewireTables\Views\Column;
1010
use Spatie\Permission\Models\Role;
1111

12-
class RolesTable extends TableComponent
12+
class RolesTable extends DataTableComponent
1313
{
14-
use HtmlComponents;
15-
16-
public $addRoute = "role.edit";
17-
public $clearSearchButton = true;
18-
1914
public function query(): Builder
2015
{
21-
return Role::query();
16+
return Role::query()
17+
->when($this->getFilter('search'), fn ($query, $term) => $query->where('name', 'like', '%'.$term.'%'));
18+
2219
}
2320

2421
public function columns(): array
2522
{
2623

2724
return [
2825
Column::make('ID', 'id')
29-
->searchable()
30-
->sortable()
31-
->format(function (Role $model) {
32-
return $this->linkRoute('role.edit', $model->id, $model->id);
33-
}),
26+
->sortable(),
3427
Column::make('Name', 'name')
35-
->searchable()
3628
->sortable(),
3729
];
3830

3931
}
32+
33+
public function getTableRowUrl($row): string
34+
{
35+
return route('role.edit', $row);
36+
}
4037
}

0 commit comments

Comments
 (0)