Loading app/Http/Controllers/ManageAdherentController.php +10 −7 Original line number Diff line number Diff line Loading @@ -8,9 +8,11 @@ class ManageAdherentController extends Controller { function index() { $users = User::select('*')->join('car_role_attribution', 'car_role_attribution.US_ID', '=', 'car_user.US_ID')->orderBy('car_user.US_ID')->get(); $users = User::select('car_user.US_ID', 'car_user.US_FIRST_NAME', 'car_user.US_NAME', 'car_role_attribution.ROL_CODE')->leftjoin('car_role_attribution', 'car_role_attribution.US_ID', '=', 'car_user.US_ID')->orderBy('car_user.US_ID')->get(); $user_role = array(); $usersInfos = array(); foreach ($users as $user) { $usersInfos[$user->US_ID] = [$user->US_ID, $user->US_FIRST_NAME, $user->US_NAME]; if (!array_key_exists($user->US_ID, $user_role)){ Loading @@ -19,19 +21,19 @@ function index() { $user_role[$user->US_ID][] = $user->ROL_CODE; } $users = [$usersInfos, $user_role]; return view('manageAdherent', ['users' => $users]); } function update(Request $request) { @dd($request->all()); $uptUser = $request->all(); RoleAttribution::truncate(); foreach ($uptUser as $key => $value) { if ($key != '_token') { $user = User::find($key); $key = $userRole = RoleAttribution::select('*')->where('US_ID', '=', $key)->get(); $user->ROL_CODE = $value; $user->save(); $roleAttribution = new RoleAttribution(); $roleAttribution->US_ID = explode("_", $key)[1]; $roleAttribution->ROL_CODE = $value; $roleAttribution->save(); } } return redirect()->route('manage_members'); Loading @@ -39,3 +41,4 @@ function update(Request $request) { } resources/views/manageAdherent.blade.php +3 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,9 @@ </tr> </thead> <tbody> @for ($i = 1; $i < count($users[0]); $i++) @foreach ($users[0] as $i => $value) <tr class="odd:bg-white even:bg-gray-50 border-b"> <td class="px-6 py-4">{{ $users[0][$i][1] . " " . $users[0][$i][2] }}</td> <td class="px-6 py-4">{{ $users[0][$i][1] . " " . strtoupper($users[0][$i][2]) }}</td> <td class="px-6 py-4"> <input type="checkbox" id="checkbox{{ $users[0][$i][0] }}" name="checkbox_{{ $users[0][$i][0] }}_DIV" value="DIV" @if(array_search('DIV', $users[1][$i]) !== false) checked @endif> </td> Loading @@ -30,7 +30,7 @@ <input type="checkbox" id="checkbox{{ $users[0][$i][0] }}" name="checkbox_{{ $users[0][$i][0] }}_DIR" value="DIR" @if(array_search('DIR', $users[1][$i]) !== false) checked @endif> </td> </tr> @endfor @endforeach </tbody> </table> Loading Loading
app/Http/Controllers/ManageAdherentController.php +10 −7 Original line number Diff line number Diff line Loading @@ -8,9 +8,11 @@ class ManageAdherentController extends Controller { function index() { $users = User::select('*')->join('car_role_attribution', 'car_role_attribution.US_ID', '=', 'car_user.US_ID')->orderBy('car_user.US_ID')->get(); $users = User::select('car_user.US_ID', 'car_user.US_FIRST_NAME', 'car_user.US_NAME', 'car_role_attribution.ROL_CODE')->leftjoin('car_role_attribution', 'car_role_attribution.US_ID', '=', 'car_user.US_ID')->orderBy('car_user.US_ID')->get(); $user_role = array(); $usersInfos = array(); foreach ($users as $user) { $usersInfos[$user->US_ID] = [$user->US_ID, $user->US_FIRST_NAME, $user->US_NAME]; if (!array_key_exists($user->US_ID, $user_role)){ Loading @@ -19,19 +21,19 @@ function index() { $user_role[$user->US_ID][] = $user->ROL_CODE; } $users = [$usersInfos, $user_role]; return view('manageAdherent', ['users' => $users]); } function update(Request $request) { @dd($request->all()); $uptUser = $request->all(); RoleAttribution::truncate(); foreach ($uptUser as $key => $value) { if ($key != '_token') { $user = User::find($key); $key = $userRole = RoleAttribution::select('*')->where('US_ID', '=', $key)->get(); $user->ROL_CODE = $value; $user->save(); $roleAttribution = new RoleAttribution(); $roleAttribution->US_ID = explode("_", $key)[1]; $roleAttribution->ROL_CODE = $value; $roleAttribution->save(); } } return redirect()->route('manage_members'); Loading @@ -39,3 +41,4 @@ function update(Request $request) { }
resources/views/manageAdherent.blade.php +3 −3 Original line number Diff line number Diff line Loading @@ -14,9 +14,9 @@ </tr> </thead> <tbody> @for ($i = 1; $i < count($users[0]); $i++) @foreach ($users[0] as $i => $value) <tr class="odd:bg-white even:bg-gray-50 border-b"> <td class="px-6 py-4">{{ $users[0][$i][1] . " " . $users[0][$i][2] }}</td> <td class="px-6 py-4">{{ $users[0][$i][1] . " " . strtoupper($users[0][$i][2]) }}</td> <td class="px-6 py-4"> <input type="checkbox" id="checkbox{{ $users[0][$i][0] }}" name="checkbox_{{ $users[0][$i][0] }}_DIV" value="DIV" @if(array_search('DIV', $users[1][$i]) !== false) checked @endif> </td> Loading @@ -30,7 +30,7 @@ <input type="checkbox" id="checkbox{{ $users[0][$i][0] }}" name="checkbox_{{ $users[0][$i][0] }}_DIR" value="DIR" @if(array_search('DIR', $users[1][$i]) !== false) checked @endif> </td> </tr> @endfor @endforeach </tbody> </table> Loading