im managing my registerd users... now i want see which user have which permission according the her/his role .. i want to show permissions in check box and make them check if user have that role. problem is target user permission according her role
my controller to view target user permission:
public function view(Request $request, User $user){
$roles = Role::with('permissions')->get();
$permissions = Permission::get();
return view('adminarea.roles.view', compact('roles','user', 'permissions'));
}
Blade file:
@foreach ( $permissions as $per )
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="permissions_ids[]" id="permissions"
value="" style="margin-right:5px" @if (?)
checked="true"
@endif>
<label class="custom-control-label" for="permissions"></label>
</div>
@endforeach
Model Relations :
Role table:
public function users()
{
return $this
->belongsToMany('App\User')
->withTimestamps();
}
public function permissions()
{
return $this->belongsToMany(Permission::class, 'roles_permissions');
}
Permission table:
public function roles()
{
return $this->belongsToMany(Role::class, 'roles_permissions');
}
User table:
public function roles()
{
return $this->belongsToMany(Role::class, 'users_roles');
}
Table Structure :
this is my roles_permission schema:
Schema::create('roles_permissions', function (Blueprint $table) {
$table->unsignedBigInteger('role_id');
$table->unsignedBigInteger('permission_id');
//FOREIGN KEY CONSTRAINTS
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
//SETTING THE PRIMARY KEYS
$table->primary(['role_id', 'permission_id']);
});
and users_role schema :
Schema::create('users_roles', function (Blueprint $table) {
$table->unsignedBigInteger('user_id');
$table->unsignedBigInteger('role_id');
//FOREIGN KEY CONSTRAINTS
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
//SETTING THE PRIMARY KEYS
$table->primary(['user_id', 'role_id']);
});
permission table :
Schema::create('permissions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
and role table schema:
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Ks9yUk
via IFTTT
Aucun commentaire:
Enregistrer un commentaire