2021-06-26 17:23:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Auth\Permissions;
|
2018-09-25 13:30:50 +02:00
|
|
|
|
|
|
|
use BookStack\Auth\Role;
|
|
|
|
use BookStack\Model;
|
2021-11-20 15:03:56 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2015-08-29 16:03:42 +02:00
|
|
|
|
2020-08-04 15:55:01 +02:00
|
|
|
/**
|
|
|
|
* @property int $id
|
|
|
|
*/
|
2016-05-01 22:20:50 +02:00
|
|
|
class RolePermission extends Model
|
2015-08-29 16:03:42 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The roles that belong to the permission.
|
|
|
|
*/
|
2021-11-20 15:03:56 +01:00
|
|
|
public function roles(): BelongsToMany
|
2015-08-29 16:03:42 +02:00
|
|
|
{
|
2018-01-28 17:58:52 +01:00
|
|
|
return $this->belongsToMany(Role::class, 'permission_role', 'permission_id', 'role_id');
|
2015-08-29 16:03:42 +02:00
|
|
|
}
|
2016-02-27 20:24:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the permission object by name.
|
|
|
|
*/
|
2021-11-20 15:03:56 +01:00
|
|
|
public static function getByName(string $name): ?RolePermission
|
2016-02-27 20:24:42 +01:00
|
|
|
{
|
|
|
|
return static::where('name', '=', $name)->first();
|
|
|
|
}
|
2015-08-29 16:03:42 +02:00
|
|
|
}
|