File tree Expand file tree Collapse file tree 9 files changed +233
-122
lines changed
resources/views/admin/users Expand file tree Collapse file tree 9 files changed +233
-122
lines changed Original file line number Diff line number Diff line change @@ -24,13 +24,14 @@ class UserController extends Controller
24
24
*/
25
25
public function index ()
26
26
{
27
- $ users = User::whereNotIn ('id ' , [auth ()->id ()])->get ();
27
+ $ index = app (AdminUserForm::class)->index ();
28
+
28
29
$ invites = Invite::where ([
29
30
'model_id ' => null ,
30
31
])->get ();
31
32
32
33
return view ('admin.users.index ' )
33
- ->with (compact ('users ' , 'invites ' ));
34
+ ->with (compact ('index ' , 'invites ' ));
34
35
}
35
36
36
37
/**
@@ -41,17 +42,15 @@ public function index()
41
42
*/
42
43
public function search (Request $ request )
43
44
{
44
- $ users = app (User::class)
45
- ->search ($ request ->search )
46
- ->get ();
45
+ $ query = app (User::class)->search ($ request ->search );
46
+ $ index = app (AdminUserForm::class)->index ($ query );
47
47
48
48
$ invites = Invite::where ([
49
49
'model_id ' => null ,
50
50
])->get ();
51
51
52
52
return view ('admin.users.index ' )
53
- ->with ('users ' , $ users )
54
- ->with ('invites ' , $ invites );
53
+ ->with (compact ('index ' , 'invites ' ));
55
54
}
56
55
57
56
/**
Original file line number Diff line number Diff line change 4
4
5
5
use App \Models \Role ;
6
6
use App \Models \User ;
7
- use Grafite \FormMaker \Fields \Bootstrap \HasMany ;
8
- use Grafite \FormMaker \Fields \Email ;
9
7
use Grafite \FormMaker \Fields \Text ;
8
+ use Grafite \FormMaker \Fields \Email ;
9
+ use Grafite \FormMaker \Fields \Hidden ;
10
10
use Grafite \FormMaker \Forms \ModelForm ;
11
+ use Grafite \FormMaker \Fields \Bootstrap \HasMany ;
11
12
12
13
class AdminUserForm extends ModelForm
13
14
{
14
15
public $ model = User::class;
15
16
16
17
public $ routePrefix = 'admin.users ' ;
17
18
19
+ public $ with = [
20
+ 'roles '
21
+ ];
22
+
23
+ public $ confirmMessage = 'Are you sure you want to delete this user? ' ;
24
+
25
+ public $ confirmMethod = 'confirmation ' ;
26
+
18
27
public $ buttons = [
19
28
'submit ' => 'Save ' ,
29
+ 'edit ' => '<span class="fas fa-fw fa-pencil-alt"></span> Edit ' ,
20
30
'delete ' => '<span class="fas fa-fw fa-trash"></span> Delete '
21
31
];
22
32
@@ -25,6 +35,7 @@ class AdminUserForm extends ModelForm
25
35
public $ buttonClasses = [
26
36
'submit ' => 'btn btn-primary ' ,
27
37
'cancel ' => 'btn btn-secondary ' ,
38
+ 'edit ' => 'btn btn-outline-primary btn-sm mr-2 ' ,
28
39
'delete ' => 'btn btn-outline-danger btn-sm ' ,
29
40
];
30
41
@@ -33,12 +44,16 @@ public function fields()
33
44
return [
34
45
Text::make ('name ' , [
35
46
'required ' => true ,
47
+ 'sortable ' => true ,
36
48
]),
37
49
Email::make ('email ' , [
38
50
'required ' => true ,
51
+ 'sortable ' => true ,
39
52
]),
53
+ Hidden::make ('role ' ),
40
54
HasMany::make ('roles ' , [
41
55
'required ' => true ,
56
+ 'visible ' => false ,
42
57
'model ' => Role::class,
43
58
'model_options ' => [
44
59
'label ' => 'label ' ,
Original file line number Diff line number Diff line change 6
6
7
7
trait HasRoles
8
8
{
9
+ public function getRoleAttribute ()
10
+ {
11
+ return $ this ->roles ()->first ()->label ;
12
+ }
13
+
9
14
/**
10
15
* User Roles.
11
16
*
Original file line number Diff line number Diff line change 5
5
use Illuminate \Auth \Events \Registered ;
6
6
use Illuminate \Auth \Listeners \SendEmailVerificationNotification ;
7
7
use Illuminate \Foundation \Support \Providers \EventServiceProvider as ServiceProvider ;
8
- use Illuminate \Support \Facades \Event ;
9
8
10
9
class EventServiceProvider extends ServiceProvider
11
10
{
Original file line number Diff line number Diff line change 26
26
"require-dev" : {
27
27
"facade/ignition" : " ^2.0" ,
28
28
"fzaninotto/faker" : " ^1.9" ,
29
+ "itsgoingd/clockwork" : " ^4.1" ,
29
30
"laravel/dusk" : " ^5.9" ,
30
31
"mockery/mockery" : " ^1.3" ,
31
32
"nunomaduro/collision" : " ^4.1" ,
You can’t perform that action at this time.
0 commit comments