1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace App \Models ;
4
6
5
- use Illuminate \Contracts \ Auth \ MustVerifyEmail ;
7
+ use Illuminate \Database \ Eloquent \ Factories \ HasFactory ;
6
8
use Illuminate \Foundation \Auth \User as Authenticatable ;
7
9
use Illuminate \Notifications \Notifiable ;
8
10
use Illuminate \Support \Facades \DB ;
11
+ use Spatie \Permission \Models \Role ;
9
12
use Spatie \Permission \Traits \HasRoles ;
10
13
11
14
class Admin extends Authenticatable
12
15
{
13
- use Notifiable, HasRoles;
16
+ use Notifiable, HasRoles, HasFactory ;
14
17
15
18
/**
16
19
* Set the default guard for this model.
@@ -25,7 +28,9 @@ class Admin extends Authenticatable
25
28
* @var array
26
29
*/
27
30
protected $ fillable = [
28
- 'name ' , 'email ' , 'password ' ,
31
+ 'name ' ,
32
+ 'email ' ,
33
+ 'password ' ,
29
34
];
30
35
31
36
/**
@@ -34,7 +39,8 @@ class Admin extends Authenticatable
34
39
* @var array
35
40
*/
36
41
protected $ hidden = [
37
- 'password ' , 'remember_token ' ,
42
+ 'password ' ,
43
+ 'remember_token ' ,
38
44
];
39
45
40
46
/**
@@ -48,31 +54,28 @@ class Admin extends Authenticatable
48
54
49
55
public static function getpermissionGroups ()
50
56
{
51
- $ permission_groups = DB ::table ('permissions ' )
57
+ return DB ::table ('permissions ' )
52
58
->select ('group_name as name ' )
53
59
->groupBy ('group_name ' )
54
60
->get ();
55
- return $ permission_groups ;
56
61
}
57
62
58
- public static function getpermissionsByGroupName ($ group_name )
63
+ public static function getpermissionsByGroupName (string $ group_name )
59
64
{
60
- $ permissions = DB ::table ('permissions ' )
65
+ return DB ::table ('permissions ' )
61
66
->select ('name ' , 'id ' )
62
67
->where ('group_name ' , $ group_name )
63
68
->get ();
64
- return $ permissions ;
65
69
}
66
70
67
- public static function roleHasPermissions ($ role , $ permissions )
71
+ public static function roleHasPermissions (Role $ role , array $ permissions ): bool
68
72
{
69
- $ hasPermission = true ;
70
73
foreach ($ permissions as $ permission ) {
71
74
if (!$ role ->hasPermissionTo ($ permission ->name )) {
72
- $ hasPermission = false ;
73
- return $ hasPermission ;
75
+ return false ;
74
76
}
75
77
}
76
- return $ hasPermission ;
78
+
79
+ return true ; // ensure returning true if all permissions are granted
77
80
}
78
81
}
0 commit comments