I have categories and basically what I want to do is give the ability to give categories their own list of roles and permissions as if the category is its own sub of a forum. While still having site wide roles and permissions. You can think of site Admins as ones who control all the categories admins:
| Cat_A | Cat_B |
| ------------- | ------------- |
| Admin | Admin |
| User | User |
| Guest | Guest |
| Mod | Mod |
The posts to categories is rather simple:
categories: id, parent_id (nullable), ...
posts: id, category_id, ...
// Category
parent -> $this->belongsTo(self::class)
children -> $this->hasMany(self::class, 'parent_id')
posts -> $this->hasMany(Post::class)
// Post
category -> $this->belongsTo(Category::class)
I think I want it so the users can belong to many categories and categories can have many users with many different roles in many different categories across the site. Here's the roles and permissions I want to use:
note I think at the start there won't be enough permissions for a permissions table. I'm just adding it there any ways.
//roles
$table->increments('id');
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
//permissions table
$table->increments('id');
$table->string('name');
$table->string('label')->nullable();
$table->timestamps();
//permission_role table
$table->integer('permission_id')->unsigned();
$table->integer('role_id')->unsigned();
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->primary(['permission_Id', 'role_id']);
//role_user
$table->integer('role_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['role_id', 'user_id']);
I’m having trouble trying to figure out the table structure and relationship structure for this though. I’m basically wondering what tables and model relationships I would need to connect my categories schema to my roles and permissions schema. Thank you for your help.