Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 5ec06e6

Browse files
committed
assign multiple roles to user
1 parent 6fc3dc0 commit 5ec06e6

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class UpdateRolesTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('roles', function (Blueprint $table) {
17+
$table->text('description');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('roles', function (Blueprint $table) {
29+
$table->dropColumn('description');
30+
});
31+
}
32+
}

resources/views/user-ui/role.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
<x-jet-input id="name" type="text" class="mt-1 block w-full" wire:model.defer="role.name" autocomplete="name"/>
2222
<x-jet-input-error for="role.name" class="mt-2"/>
2323
</div>
24+
<div class="col-span-6 sm:col-span-4">
25+
<x-jet-label for="description" value="{{ __('Role description') }}"/>
26+
<x-jet-input id="description" type="text" class="mt-1 block w-full" wire:model.defer="role.description" autocomplete="description"/>
27+
<x-jet-input-error for="role.description" class="mt-2"/>
28+
</div>
2429
</x-slot>
2530
<x-slot name="actions">
2631
<x-jet-action-message class="mr-3" on="saved">

src/Http/Livewire/Role.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ class Role extends Component
1010
use HandlesPermissions;
1111

1212
public $role;
13+
public $description;
1314

1415
protected function rules()
1516
{
1617
return [
1718
'role.name' => 'required|string',
19+
'role.description' => 'required|string',
1820
];
1921
}
2022

src/Http/Livewire/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function mount(\App\Models\User $user)
2929
{
3030
$this->user = $user;
3131
$this->forUser($this->user);
32-
$this->userRoles = $this->user->roles->pluck('id');
32+
$this->userRoles = array_map('strval', $this->user->roles->pluck('id')->toArray());
3333
}
3434

3535
public function render()

0 commit comments

Comments
 (0)