init commit
This commit is contained in:
commit
c9d982669a
461 changed files with 30317 additions and 0 deletions
42
app/Models/Permission.php
Normal file
42
app/Models/Permission.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Permission extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'display_name',
|
||||
'description',
|
||||
'is_wildcard'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_wildcard' => 'boolean'
|
||||
];
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class)->withpivot('granted')->withTimestamps();
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class)->withPivot('granted')->withTimestamps();
|
||||
}
|
||||
|
||||
public function matches($permission)
|
||||
{
|
||||
if (!$this->is_wildcard) {
|
||||
return $this->name === $permission;
|
||||
}
|
||||
|
||||
$pattern = str_replace('*', '.*', $this->name);
|
||||
return preg_match('/^' . $pattern . '$/', $permission);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue