File tree 2 files changed +8
-28
lines changed
2 files changed +8
-28
lines changed Original file line number Diff line number Diff line change @@ -15,15 +15,14 @@ trait HasPermissions
15
15
*/
16
16
public function givePermissionTo (...$ permissions )
17
17
{
18
- collect ($ permissions )
18
+ $ permissions = collect ($ permissions )
19
19
->flatten ()
20
20
->map (function ($ permission ) {
21
21
return $ this ->getStoredPermission ($ permission );
22
- })
23
- ->each (function (Permission $ permission ) {
24
- return $ this ->permissions ()->save ($ permission );
25
22
});
26
23
24
+ $ this ->permissions ()->saveMany ($ permissions );
25
+
27
26
$ this ->forgetCachedPermissions ();
28
27
29
28
return $ this ;
@@ -40,17 +39,7 @@ public function syncPermissions(...$permissions)
40
39
{
41
40
$ this ->permissions ()->detach ();
42
41
43
- collect ($ permissions )
44
- ->flatten ()
45
- ->map (function ($ permission ) {
46
- return $ this ->getStoredPermission ($ permission );
47
- })->each (function (Permission $ permission ) {
48
- $ this ->permissions ()->save ($ permission );
49
- });
50
-
51
- $ this ->forgetCachedPermissions ();
52
-
53
- return $ this ;
42
+ return $ this ->givePermissionTo ($ permissions );
54
43
}
55
44
56
45
/**
Original file line number Diff line number Diff line change @@ -45,15 +45,14 @@ public function permissions()
45
45
*/
46
46
public function assignRole (...$ roles )
47
47
{
48
- collect ($ roles )
48
+ $ roles = collect ($ roles )
49
49
->flatten ()
50
50
->map (function ($ role ) {
51
51
return $ this ->getStoredRole ($ role );
52
- })
53
- ->each (function (Role $ role ) {
54
- return $ this ->roles ()->save ($ role );
55
52
});
56
53
54
+ $ this ->roles ()->saveMany ($ roles );
55
+
57
56
$ this ->forgetCachedPermissions ();
58
57
59
58
return $ this ;
@@ -80,15 +79,7 @@ public function syncRoles(...$roles)
80
79
{
81
80
$ this ->roles ()->detach ();
82
81
83
- collect ($ roles )
84
- ->flatten ()
85
- ->map (function ($ role ) {
86
- return $ this ->getStoredRole ($ role );
87
- })->each (function (Role $ role ) {
88
- $ this ->roles ()->save ($ role );
89
- });
90
-
91
- return $ this ;
82
+ return $ this ->assignRole ($ roles );
92
83
}
93
84
94
85
/**
You can’t perform that action at this time.
0 commit comments