1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Models; |
17
|
|
|
|
18
|
|
|
use Illuminate\Database\Eloquent\Model; |
19
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
20
|
|
|
|
21
|
|
|
class Role extends Model |
22
|
|
|
{ |
23
|
|
|
use SoftDeletes; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected $dates = ['deleted_at']; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
protected $fillable = [ |
34
|
|
|
'slug', |
35
|
|
|
'title', |
36
|
|
|
'description', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
protected $with = ['abilities']; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Create a new Eloquent model instance. |
46
|
|
|
* |
47
|
|
|
* @param array $attributes |
48
|
|
|
* |
49
|
|
|
* @return void |
|
|
|
|
50
|
|
|
*/ |
51
|
|
|
public function __construct(array $attributes = []) |
52
|
|
|
{ |
53
|
|
|
parent::__construct($attributes); |
54
|
|
|
|
55
|
|
|
$this->setTable(config('rinvex.fort.tables.roles')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* A role may be given various abilities. |
60
|
|
|
* |
61
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
62
|
|
|
*/ |
63
|
|
|
public function abilities() |
64
|
|
|
{ |
65
|
|
|
return $this->belongsToMany(config('rinvex.fort.models.ability'), config('rinvex.fort.tables.ability_role')) |
66
|
|
|
->withTimestamps(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* A role may be assigned to various users. |
71
|
|
|
* |
72
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
73
|
|
|
*/ |
74
|
|
|
public function users() |
75
|
|
|
{ |
76
|
|
|
return $this->belongsToMany(config('rinvex.fort.models.user'), config('rinvex.fort.tables.role_user')) |
77
|
|
|
->withTimestamps(); |
78
|
|
|
} |
79
|
|
|
/** |
80
|
|
|
* Determine if the role is super admin. |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function isSuperadmin() |
85
|
|
|
{ |
86
|
|
|
return $this->abilities->where('policy', null)->contains('action', 'superadmin'); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Determine if the role is protected. |
91
|
|
|
* |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
|
|
public function isProtected() |
95
|
|
|
{ |
96
|
|
|
return in_array($this->id, config('rinvex.fort.protected.roles')); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.