|
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 Ability 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
|
|
|
'action', |
|
35
|
|
|
'policy', |
|
36
|
|
|
'title', |
|
37
|
|
|
'description', |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Create a new Eloquent model instance. |
|
42
|
|
|
* |
|
43
|
|
|
* @param array $attributes |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
|
|
|
|
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct(array $attributes = []) |
|
48
|
|
|
{ |
|
49
|
|
|
parent::__construct($attributes); |
|
50
|
|
|
|
|
51
|
|
|
$this->setTable(config('rinvex.fort.tables.abilities')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* An ability can be applied to roles. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
58
|
|
|
*/ |
|
59
|
|
|
public function roles() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->belongsToMany(config('rinvex.fort.models.role'), config('rinvex.fort.tables.ability_role')) |
|
62
|
|
|
->withTimestamps(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* An ability can be applied to users. |
|
67
|
|
|
* |
|
68
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
|
69
|
|
|
*/ |
|
70
|
|
|
public function users() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->belongsToMany(config('rinvex.fort.models.user'), config('rinvex.fort.tables.ability_user')) |
|
73
|
|
|
->withTimestamps(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Determine if the ability is super admin. |
|
78
|
|
|
* |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
|
|
public function isSuperadmin() |
|
82
|
|
|
{ |
|
83
|
|
|
return ! $this->policy && $this->action === 'superadmin'; |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Determine if the ability is protected. |
|
88
|
|
|
* |
|
89
|
|
|
* @return bool |
|
90
|
|
|
*/ |
|
91
|
|
|
public function isProtected() |
|
92
|
|
|
{ |
|
93
|
|
|
return in_array($this->id, config('rinvex.fort.protected.abilities')); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
Adding a
@returnannotation 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.