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