]> BookStack Code Mirror - bookstack/blob - app/Permissions/Models/RolePermission.php
API: Added test to cover system info endpoint
[bookstack] / app / Permissions / Models / RolePermission.php
1 <?php
2
3 namespace BookStack\Permissions\Models;
4
5 use BookStack\App\Model;
6 use BookStack\Users\Models\Role;
7 use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8
9 /**
10  * @property int $id
11  * @property string $name
12  * @property string $display_name
13  */
14 class RolePermission extends Model
15 {
16     /**
17      * The roles that belong to the permission.
18      */
19     public function roles(): BelongsToMany
20     {
21         return $this->belongsToMany(Role::class, 'permission_role', 'permission_id', 'role_id');
22     }
23
24     /**
25      * Get the permission object by name.
26      */
27     public static function getByName(string $name): ?RolePermission
28     {
29         return static::where('name', '=', $name)->first();
30     }
31 }