I setup default laravel-permission package (spatie). Here, I am going to add one model, Team. So we can make team model like this.
<?php
namespace App\Models;
class Team extends BaseModel
{
public function users()
{
return $this->belongsToMany('App\Models\User', 'team_users', 'team_id', 'user_id')->withTimestamps();
}
}
Of course, there are user roles too such as master admin, admin, client, employee, user
. I am going to assign permission to team like role - permission
relation.
So I made model_has_team,
team_has_permission
table.
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->unsignedBigInteger('permission_id');
$table->unsignedBigInteger('team_id');
$table->foreign('permission_id')
->references('id')
->on($tableNames['permissions'])
->onDelete('cascade');
$table->foreign('team_id')
->references('id')
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary(['permission_id', 'team_id'], 'role_has_permissions_permission_id_role_id_primary');
});
And how can I use this in view or controller?
user-team-permission
user-permission
user-role-permission
For one permission, I think I should consider above three permissions. Can anyone help me?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire