feat(roles): tambah fitur relasi posisi pada role
- Tambahkan relasi posisi dengan menambahkan kolom `position_id` pada tabel roles melalui migrasi. - Perbarui fungsi pada `RolesController` untuk menyertakan posisi dalam proses CRUD. - Gunakan model `Position` untuk mendapatkan daftar posisi baik saat membuat maupun mengedit role. - Sesuaikan nama permission dari `roles.view` ke `roles.read`, `roles.store` ke `roles.create`, dan `roles.edit` ke `roles.update` agar konsisten. - Perbarui validasi di `RoleRequest` untuk mendukung input `position_id`. - Tambahkan properti `position_id` ke atribut `fillable` di model Role untuk mendukung mass assignment. - Buat fungsi relasi `position()` pada model Role untuk mereferensikan ke model Position. - Perbarui tampilan form role (`create.blade.php`): - Tambahkan dropdown untuk memilih posisi dalam form input. - Tampilkan informasi level posisi bersama dengan nama posisi dalam dropdown. - Sinkronisasi validasi dan nilai default sesuai dengan pengaturan posisi. - Perbaikan minor pada query pencarian data roles, menggunakan `whereRaw` untuk pencarian case-insensitive.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
use Modules\Usermanagement\Http\Requests\RoleRequest;
|
||||
use Modules\Usermanagement\Models\Permission;
|
||||
use Modules\Usermanagement\Models\PermissionGroup;
|
||||
use Modules\Usermanagement\Models\Position;
|
||||
use Modules\Usermanagement\Models\Role;
|
||||
|
||||
/**
|
||||
@@ -48,7 +49,7 @@
|
||||
public function index()
|
||||
{
|
||||
// Check if the authenticated user has the required permission to view roles
|
||||
if (is_null($this->user) || !$this->user->can('roles.view')) {
|
||||
if (is_null($this->user) || !$this->user->can('roles.read')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view roles.');
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@
|
||||
public function store(RoleRequest $request)
|
||||
{
|
||||
// Check if the authenticated user has the required permission to store roles
|
||||
if (is_null($this->user) || !$this->user->can('roles.store')) {
|
||||
if (is_null($this->user) || !$this->user->can('roles.create')) {
|
||||
//abort(403, 'Sorry! You are not allowed to store roles.');
|
||||
}
|
||||
|
||||
@@ -115,8 +116,9 @@
|
||||
}
|
||||
|
||||
$permissiongroups = PermissionGroup::all();
|
||||
$positions = Position::all();
|
||||
// Return the view for creating a new role
|
||||
return view('usermanagement::roles.create',compact('permissiongroups'));
|
||||
return view('usermanagement::roles.create', compact('permissiongroups', 'positions'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,7 +132,7 @@
|
||||
public function show($id)
|
||||
{
|
||||
// Check if the authenticated user has the required permission to view roles
|
||||
if (is_null($this->user) || !$this->user->can('roles.view')) {
|
||||
if (is_null($this->user) || !$this->user->can('roles.read')) {
|
||||
abort(403, 'Sorry! You are not allowed to view roles.');
|
||||
}
|
||||
|
||||
@@ -154,7 +156,7 @@
|
||||
public function edit($id)
|
||||
{
|
||||
// Check if the authenticated user has the required permission to edit roles
|
||||
if (is_null($this->user) || !$this->user->can('roles.edit')) {
|
||||
if (is_null($this->user) || !$this->user->can('roles.update')) {
|
||||
//abort(403, 'Sorry! You are not allowed to edit roles.');
|
||||
}
|
||||
|
||||
@@ -162,8 +164,9 @@
|
||||
$role = Role::find($id);
|
||||
$permissions = Permission::all();
|
||||
$permissiongroups = PermissionGroup::all();
|
||||
$positions = Position::all();
|
||||
// Return the view for editing the role
|
||||
return view('usermanagement::roles.create', compact('role','permissions','permissiongroups'));
|
||||
return view('usermanagement::roles.create', compact('role', 'permissions', 'permissiongroups', 'positions'));
|
||||
}
|
||||
|
||||
|
||||
@@ -272,7 +275,7 @@
|
||||
*/
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('roles.view')) {
|
||||
if (is_null($this->user) || !$this->user->can('roles.read')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
@@ -283,7 +286,7 @@
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'LIKE', "%$search%");
|
||||
$q->whereRaw('LOWER(name) LIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
$rules = [
|
||||
'guard_names' => 'required|string|in:web,api',
|
||||
'position_id' => 'nullable|exists:positions,id',
|
||||
];
|
||||
|
||||
if ($this->method() === 'PUT') {
|
||||
@@ -41,6 +42,3 @@
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user