From d40747ef3ded43fb267c864f92080da3a4ac351e Mon Sep 17 00:00:00 2001 From: Watiah11 Date: Fri, 10 May 2024 15:31:41 +0700 Subject: [PATCH] fix: role menu --- app/Http/Controllers/RoleMenuController.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/RoleMenuController.php b/app/Http/Controllers/RoleMenuController.php index 2a67fca..e8073d9 100644 --- a/app/Http/Controllers/RoleMenuController.php +++ b/app/Http/Controllers/RoleMenuController.php @@ -5,25 +5,28 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Menu; use App\Models\RoleMenu; +use Illuminate\Support\Facades\Log; class RoleMenuController extends Controller { public function add(Request $request) { $this->validate($request, [ - 'role_id' => 'required', - 'menu_id' => 'required', + 'role_id.*' => 'required', + 'menu_id.*' => 'required' ]); $data = $request->all(); - $data['created_by'] = $this->currentName; - - $result = RoleMenu::create($data); - - if($result){ + $countData = 0; + foreach($data as $arrData) { + $arrData['created_by'] = $this->currentName; + $result = RoleMenu::create($arrData); + $countData++; + } + if($result && $countData > 0) { return response()->json(['status'=>'success','message'=>'add data role menu successfully!','code'=>200], 200); - }else{ + } else { return response()->json(['status'=>'failed','message'=>'add data role menu failed!','code'=>400], 400); } }