- Implemented RoleEdit component for editing roles with permissions. - Created RoleIndex component for listing roles with delete confirmation. - Added routes for role management in web.php with appropriate permissions. - Developed RoleTest to cover authentication, authorization, and data integrity for role management.
39 lines
825 B
PHP
39 lines
825 B
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Admin;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class RoleRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
$roleId = $this->route('role')?->id;
|
|
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
'string',
|
|
'max:100',
|
|
Rule::unique('roles', 'name')->ignore($roleId, 'id'),
|
|
],
|
|
'permissions' => ['present', 'array'],
|
|
'permissions.*' => ['string', 'exists:permissions,name'],
|
|
];
|
|
}
|
|
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => 'Nama Role',
|
|
'permissions' => 'Permission',
|
|
];
|
|
}
|
|
}
|