Browse Source

update CRUD permission

pull/1/head
farhantock 11 months ago
parent
commit
f88ce60ba8
  1. 22
      app/Http/Controllers/MenuController.php
  2. 2
      app/Models/RoleMenu.php

22
app/Http/Controllers/MenuController.php

@ -30,7 +30,8 @@ class MenuController extends Controller
} }
} }
public function edit($id){ public function edit($id)
{
if (!$id || (int) $id < 0 || $id == "") { if (!$id || (int) $id < 0 || $id == "") {
return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400); return response()->json(['status' => 'failed', 'message' => 'id is required!', 'code' => 400], 400);
die(); die();
@ -108,7 +109,13 @@ class MenuController extends Controller
public function listMenu($id) public function listMenu($id)
{ {
$dataParent = RoleMenu::select("m_menu.*") $dataParent = RoleMenu::select(
'm_menu.*',
"t_roles_menu.create",
"t_roles_menu.read",
"t_roles_menu.update",
"t_roles_menu.delete"
)
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->whereNull('m_menu.parent_id') ->whereNull('m_menu.parent_id')
@ -127,7 +134,13 @@ class MenuController extends Controller
protected function getChildrenMenu($id, $role_id) protected function getChildrenMenu($id, $role_id)
{ {
$dataChildren = RoleMenu::select("m_menu.*") $dataChildren = RoleMenu::select(
'm_menu.*',
"t_roles_menu.create",
"t_roles_menu.read",
"t_roles_menu.update",
"t_roles_menu.delete"
)
->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id') ->join('m_menu', 'm_menu.id', '=', 't_roles_menu.menu_id')
->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id') ->join('m_roles', 'm_roles.id', '=', 't_roles_menu.role_id')
->where('m_roles.id', $role_id) ->where('m_roles.id', $role_id)
@ -136,8 +149,7 @@ class MenuController extends Controller
->get(); ->get();
$children = []; $children = [];
if ($dataChildren) { if ($dataChildren) {
foreach($dataChildren as $data) foreach ($dataChildren as $data) {
{
$data->children = $this->getChildrenMenu($data->id, $role_id); $data->children = $this->getChildrenMenu($data->id, $role_id);
$children[] = $data; $children[] = $data;
} }

2
app/Models/RoleMenu.php

@ -12,6 +12,6 @@ class RoleMenu extends Model
const UPDATED_AT = 'updated_at'; const UPDATED_AT = 'updated_at';
protected $fillable = [ protected $fillable = [
'role_id', 'menu_id', 'created_at', 'created_by', 'updated_at', 'updated_by' 'role_id', 'menu_id', 'create', 'read', 'update', 'delete', 'created_at', 'created_by', 'updated_at', 'updated_by'
]; ];
} }

Loading…
Cancel
Save