Skip to content

Commit e533b18

Browse files
authored
Merge pull request #1525 from rappasoft/development
v8.2.0
2 parents 83f3102 + addf782 commit e533b18

File tree

21 files changed

+1334
-1183
lines changed

21 files changed

+1334
-1183
lines changed

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55

6+
## [8.2.0] - 2021-04-22
7+
8+
### Added
9+
10+
- User search scope
11+
- Role Scope class
12+
- Korean (ko) language pack (https://github.com/rappasoft/laravel-boilerplate/pull/1521)
13+
14+
### Changed
15+
16+
- Updated lock files
17+
- Updated all tables to laravel-livewire-tables 1.x
18+
- Updated to Laravel commit: a6ffdbdf416d60c38443725807a260a84dca5045
19+
20+
### Removed
21+
22+
- codedungeon/phpunit-result-printer, should use `composer test` for parallel testing.
23+
624
## [8.1.0] - 2021-04-05
725

826
### Added
@@ -435,7 +453,8 @@ Started from scratch with a blank Laravel 7.* installation. This release is not
435453
- Fix yarn tests
436454
- Fix: Socially logged in users get assigned the default role
437455

438-
[Unreleased]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.1.0...development
456+
[Unreleased]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.2.0...development
457+
[8.2.0]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.3...v8.2.0
439458
[8.1.0]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.3...v8.1.0
440459
[8.0.3]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.2...v8.0.3
441460
[8.0.2]: https://github.com/rappasoft/laravel-boilerplate/compare/v8.0.1...v8.0.2

app/Domains/Auth/Models/Role.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Domains\Auth\Models\Traits\Attribute\RoleAttribute;
66
use App\Domains\Auth\Models\Traits\Method\RoleMethod;
7+
use App\Domains\Auth\Models\Traits\Scope\RoleScope;
78
use Database\Factories\RoleFactory;
89
use Illuminate\Database\Eloquent\Factories\HasFactory;
910
use Spatie\Permission\Models\Role as SpatieRole;
@@ -15,7 +16,8 @@ class Role extends SpatieRole
1516
{
1617
use HasFactory,
1718
RoleAttribute,
18-
RoleMethod;
19+
RoleMethod,
20+
RoleScope;
1921

2022
/**
2123
* @var string[]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Domains\Auth\Models\Traits\Scope;
4+
5+
/**
6+
* Class RoleScope.
7+
*/
8+
trait RoleScope
9+
{
10+
/**
11+
* @param $query
12+
* @param $term
13+
*
14+
* @return mixed
15+
*/
16+
public function scopeSearch($query, $term)
17+
{
18+
return $query->where(function ($query) use ($term) {
19+
$query->where('name', 'like', '%'.$term.'%')
20+
->orWhereHas('permissions', function ($query) use ($term) {
21+
$query->where('description', 'like', '%'.$term.'%');
22+
});
23+
});
24+
}
25+
}

app/Domains/Auth/Models/Traits/Scope/UserScope.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
*/
88
trait UserScope
99
{
10+
/**
11+
* @param $query
12+
* @param $term
13+
*
14+
* @return mixed
15+
*/
16+
public function scopeSearch($query, $term)
17+
{
18+
return $query->where(function ($query) use ($term) {
19+
$query->where('name', 'like', '%'.$term.'%')
20+
->orWhere('email', 'like', '%'.$term.'%');
21+
});
22+
}
23+
1024
/**
1125
* @param $query
1226
*

app/Http/Livewire/Backend/RolesTable.php

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,41 @@
33
namespace App\Http\Livewire\Backend;
44

55
use App\Domains\Auth\Models\Role;
6-
use App\Domains\Auth\Models\User;
76
use Illuminate\Database\Eloquent\Builder;
8-
use Rappasoft\LaravelLivewireTables\TableComponent;
9-
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
7+
use Rappasoft\LaravelLivewireTables\DataTableComponent;
108
use Rappasoft\LaravelLivewireTables\Views\Column;
119

1210
/**
1311
* Class RolesTable.
1412
*/
15-
class RolesTable extends TableComponent
13+
class RolesTable extends DataTableComponent
1614
{
17-
use HtmlComponents;
18-
19-
/**
20-
* @var string
21-
*/
22-
public $sortField = 'name';
23-
24-
/**
25-
* @var array
26-
*/
27-
protected $options = [
28-
'bootstrap.container' => false,
29-
'bootstrap.classes.table' => 'table table-striped',
30-
];
31-
3215
/**
3316
* @return Builder
3417
*/
3518
public function query(): Builder
3619
{
3720
return Role::with('permissions:id,name,description')
38-
->withCount('users');
21+
->withCount('users')
22+
->when($this->getFilter('search'), fn ($query, $term) => $query->search($term));
3923
}
4024

41-
/**
42-
* @return array
43-
*/
4425
public function columns(): array
4526
{
4627
return [
47-
Column::make(__('Type'), 'type')
48-
->sortable()
49-
->format(function (Role $model) {
50-
if ($model->type === User::TYPE_ADMIN) {
51-
return __('Administrator');
52-
}
53-
54-
if ($model->type === User::TYPE_USER) {
55-
return __('User');
56-
}
57-
58-
return 'N/A';
59-
}),
60-
Column::make(__('Name'), 'name')
61-
->searchable()
28+
Column::make(__('Type'))
29+
->sortable(),
30+
Column::make(__('Name'))
6231
->sortable(),
63-
Column::make(__('Permissions'), 'permissions_label')
64-
->searchable(function ($builder, $term) {
65-
return $builder->orWhereHas('permissions', function ($query) use ($term) {
66-
return $query->where('name', 'like', '%'.$term.'%');
67-
});
68-
})
69-
->format(function (Role $model) {
70-
return $this->html($model->permissions_label);
71-
}),
32+
Column::make(__('Permissions')),
7233
Column::make(__('Number of Users'), 'users_count')
7334
->sortable(),
74-
Column::make(__('Actions'))
75-
->format(function (Role $model) {
76-
return view('backend.auth.role.includes.actions', ['model' => $model]);
77-
}),
35+
Column::make(__('Actions')),
7836
];
7937
}
38+
39+
public function rowView(): string
40+
{
41+
return 'backend.auth.role.includes.row';
42+
}
8043
}

app/Http/Livewire/Backend/UsersTable.php

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@
44

55
use App\Domains\Auth\Models\User;
66
use Illuminate\Database\Eloquent\Builder;
7-
use Rappasoft\LaravelLivewireTables\TableComponent;
8-
use Rappasoft\LaravelLivewireTables\Traits\HtmlComponents;
7+
use Rappasoft\LaravelLivewireTables\DataTableComponent;
98
use Rappasoft\LaravelLivewireTables\Views\Column;
9+
use Rappasoft\LaravelLivewireTables\Views\Filter;
1010

1111
/**
1212
* Class UsersTable.
1313
*/
14-
class UsersTable extends TableComponent
14+
class UsersTable extends DataTableComponent
1515
{
16-
use HtmlComponents;
17-
1816
/**
19-
* @var string
17+
* @var
2018
*/
21-
public $sortField = 'name';
19+
public $status;
2220

2321
/**
24-
* @var string
22+
* @var array|string[]
2523
*/
26-
public $status;
24+
public array $sortNames = [
25+
'email_verified_at' => 'Verified',
26+
'two_factor_auth_count' => '2FA',
27+
];
2728

2829
/**
29-
* @var array
30+
* @var array|string[]
3031
*/
31-
protected $options = [
32-
'bootstrap.container' => false,
33-
'bootstrap.classes.table' => 'table table-striped',
32+
public array $filterNames = [
33+
'type' => 'User Type',
34+
'verified' => 'E-mail Verified',
3435
];
3536

3637
/**
@@ -46,18 +47,48 @@ public function mount($status = 'active'): void
4647
*/
4748
public function query(): Builder
4849
{
49-
$query = User::with('roles', 'twoFactorAuth')
50-
->withCount('twoFactorAuth');
50+
$query = User::with('roles', 'twoFactorAuth')->withCount('twoFactorAuth');
5151

5252
if ($this->status === 'deleted') {
53-
return $query->onlyTrashed();
53+
$query = $query->onlyTrashed();
54+
} elseif ($this->status === 'deactivated') {
55+
$query = $query->onlyDeactivated();
56+
} else {
57+
$query = $query->onlyActive();
5458
}
5559

56-
if ($this->status === 'deactivated') {
57-
return $query->onlyDeactivated();
58-
}
60+
return $query
61+
->when($this->getFilter('search'), fn ($query, $term) => $query->search($term))
62+
->when($this->getFilter('type'), fn ($query, $type) => $query->where('type', $type))
63+
->when($this->getFilter('active'), fn ($query, $active) => $query->where('active', $active === 'yes'))
64+
->when($this->getFilter('verified'), fn ($query, $verified) => $verified === 'yes' ? $query->whereNotNull('email_verified_at') : $query->whereNull('email_verified_at'));
65+
}
5966

60-
return $query->onlyActive();
67+
/**
68+
* @return array
69+
*/
70+
public function filters(): array
71+
{
72+
return [
73+
'type' => Filter::make('User Type')
74+
->select([
75+
'' => 'Any',
76+
User::TYPE_ADMIN => 'Administrators',
77+
User::TYPE_USER => 'Users',
78+
]),
79+
'active' => Filter::make('Active')
80+
->select([
81+
'' => 'Any',
82+
'yes' => 'Yes',
83+
'no' => 'No',
84+
]),
85+
'verified' => Filter::make('E-mail Verified')
86+
->select([
87+
'' => 'Any',
88+
'yes' => 'Yes',
89+
'no' => 'No',
90+
]),
91+
];
6192
}
6293

6394
/**
@@ -66,54 +97,27 @@ public function query(): Builder
6697
public function columns(): array
6798
{
6899
return [
69-
Column::make(__('Type'), 'type')
70-
->sortable()
71-
->format(function (User $model) {
72-
return view('backend.auth.user.includes.type', ['user' => $model]);
73-
}),
74-
Column::make(__('Name'), 'name')
75-
->searchable()
100+
Column::make(__('Type'))
101+
->sortable(),
102+
Column::make(__('Name'))
76103
->sortable(),
77104
Column::make(__('E-mail'), 'email')
78-
->searchable()
79-
->sortable()
80-
->format(function (User $model) {
81-
return $this->mailto($model->email);
82-
}),
105+
->sortable(),
83106
Column::make(__('Verified'), 'email_verified_at')
84-
->sortable()
85-
->format(function (User $model) {
86-
return view('backend.auth.user.includes.verified', ['user' => $model]);
87-
}),
88-
Column::make(__('2FA'))
89-
->sortable(function ($builder, $direction) {
90-
return $builder->orderBy('two_factor_auth_count', $direction);
91-
})
92-
->format(function (User $model) {
93-
return view('backend.auth.user.includes.2fa', ['user' => $model]);
94-
}),
95-
Column::make(__('Roles'), 'roles_label')
96-
->searchable(function ($builder, $term) {
97-
return $builder->orWhereHas('roles', function ($query) use ($term) {
98-
return $query->where('name', 'like', '%'.$term.'%');
99-
});
100-
})
101-
->format(function (User $model) {
102-
return $this->html($model->roles_label);
103-
}),
104-
Column::make(__('Additional Permissions'), 'permissions_label')
105-
->searchable(function ($builder, $term) {
106-
return $builder->orWhereHas('permissions', function ($query) use ($term) {
107-
return $query->where('name', 'like', '%'.$term.'%');
108-
});
109-
})
110-
->format(function (User $model) {
111-
return $this->html($model->permissions_label);
112-
}),
113-
Column::make(__('Actions'))
114-
->format(function (User $model) {
115-
return view('backend.auth.user.includes.actions', ['user' => $model]);
116-
}),
107+
->sortable(),
108+
Column::make(__('2FA'), 'two_factor_auth_count')
109+
->sortable(),
110+
Column::make(__('Roles')),
111+
Column::make(__('Additional Permissions')),
112+
Column::make(__('Actions')),
117113
];
118114
}
115+
116+
/**
117+
* @return string
118+
*/
119+
public function rowView(): string
120+
{
121+
return 'backend.auth.user.includes.row';
122+
}
119123
}

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"laravel/tinker": "^2.5",
2424
"laravel/ui": "^3.0",
2525
"livewire/livewire": "^2.0",
26-
"rappasoft/laravel-livewire-tables": "^0.3",
26+
"rappasoft/laravel-livewire-tables": "^1.0",
2727
"rappasoft/lockout": "^3.0",
2828
"spatie/laravel-activitylog": "^3.14",
2929
"spatie/laravel-permission": "^3.11",
@@ -33,7 +33,6 @@
3333
"barryvdh/laravel-debugbar": "^3.2",
3434
"barryvdh/laravel-ide-helper": "^2.6",
3535
"brianium/paratest": "^6.2",
36-
"codedungeon/phpunit-result-printer": "^0.29",
3736
"facade/ignition": "^2.5",
3837
"fakerphp/faker": "^1.9.1",
3938
"friendsofphp/php-cs-fixer": "^2.16",

0 commit comments

Comments
 (0)