|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models\enso\Permissions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Support\Facades\Route; |
|
7
|
|
|
use App\Models\enso\Menus\Menu; |
|
8
|
|
|
use LaravelEnso\Permissions\App\Enums\Types; |
|
9
|
|
|
use LaravelEnso\Permissions\App\Enums\Verbs; |
|
10
|
|
|
use LaravelEnso\Permissions\App\Exceptions\Permission as Exception; |
|
11
|
|
|
use App\Models\Roles\Role; |
|
|
|
|
|
|
12
|
|
|
use LaravelEnso\Roles\App\Traits\HasRoles; |
|
13
|
|
|
use LaravelEnso\Tables\App\Traits\TableCache; |
|
14
|
|
|
use App\Models\Tutorials\Tutorial; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @property int $id |
|
18
|
|
|
* @property string $name |
|
19
|
|
|
* @property string $description |
|
20
|
|
|
* @property boolean $is_default |
|
21
|
|
|
* @property string $created_at |
|
22
|
|
|
* @property string $updated_at |
|
23
|
|
|
* @property Menu[] $menuses |
|
24
|
|
|
* @property PermissionRole[] $permissionRoles |
|
25
|
|
|
* @property Tutorial[] $tutorials |
|
26
|
|
|
*/ |
|
27
|
|
|
class Permission extends Model |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* The table associated with the model. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $table = 'permissions'; |
|
35
|
|
|
|
|
36
|
|
|
use HasRoles, TableCache; |
|
37
|
|
|
|
|
38
|
|
|
protected $fillable = ['name', 'description', 'is_default']; |
|
39
|
|
|
|
|
40
|
|
|
protected $casts = ['is_default' => 'boolean']; |
|
41
|
|
|
|
|
42
|
|
|
public function menu() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->hasOne(Menu::class); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function roles() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->belongsToMany(Role::class); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function tutorials() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->hasMany(Tutorial::class); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getTypeAttribute() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->type(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function type() |
|
63
|
|
|
{ |
|
64
|
|
|
if ($this->relationLoaded('menu') && $this->menu !== null) { |
|
65
|
|
|
return Types::Menu; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return Verbs::get($this->method()) ?? Types::Link; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function method() |
|
72
|
|
|
{ |
|
73
|
|
|
$methods = optional(Route::getRoutes()->getByName($this->name))->methods(); |
|
74
|
|
|
|
|
75
|
|
|
return $methods[0] ?? null; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function scopeImplicit($query) |
|
79
|
|
|
{ |
|
80
|
|
|
return $query->whereIsDefault(true); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function delete() |
|
84
|
|
|
{ |
|
85
|
|
|
if ($this->roles()->exists()) { |
|
86
|
|
|
throw Exception::roles(); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if ($this->menu()->exists()) { |
|
90
|
|
|
throw Exception::menu(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
parent::delete(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths