Skip to content

Commit

Permalink
Updated user editing for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling committed Jan 26, 2021
1 parent def6b30 commit e5a523d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

<a name="0.2.2"></a>
## [0.2.2](https://github.com/P3D-Legacy/skin.pokemon3d.net/compare/0.2.1...0.2.2)

> 2021-01-26
### Updated

* Updated user editing for admins


<a name="0.2.1"></a>
## [0.2.1](https://github.com/P3D-Legacy/skin.pokemon3d.net/compare/0.2.0...0.2.1)

Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public function show($id)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
public function edit($gjid)
{
$user = GJUser::find($id)->first();
$user = GJUser::where('gjid', $gjid)->first();
abort_unless($user, 403);
return view('user.edit')->with('user', $user);
}

Expand All @@ -73,12 +74,13 @@ public function edit($id)
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
public function update(Request $request, $gjid)
{
$request->validate([
'is_admin' => ['required', 'boolean']
]);
$user = GJUser::find($id)->first();
$user = GJUser::where('gjid', $gjid)->first();
abort_unless($user, 403);
$user->is_admin = $request->is_admin;
$user->save();
return redirect()->route('users')->with('success', 'User saved.');
Expand Down
2 changes: 1 addition & 1 deletion resources/views/user/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<td>{{ $user->gjid }}</td>
<td>{{ $user->gju }}</td>
<td>{{ ($user->is_admin) ? 'Yes' : 'No' }}</td>
<td><a class="btn btn-warning" href="{{ route('user-edit', $user->id) }}"><i class="fas fa-edit"></i> Edit</a></td>
<td><a class="btn btn-warning" href="{{ route('user-edit', $user->gjid) }}"><i class="fas fa-edit"></i> Edit</a></td>
</tr>
@endforeach
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
Route::post('/skin/delete/{id}', [SkinController::class, 'destroyAsAdmin'])->name('skin-destroy-admin');

Route::get('/users', [UserController::class, 'index'])->name('users');
Route::get('/user/edit/{id}', [UserController::class, 'edit'])->name('user-edit');
Route::post('/user/edit/{id}', [UserController::class, 'update'])->name('user-update');
Route::get('/user/edit/{gjid}', [UserController::class, 'edit'])->name('user-edit');
Route::post('/user/edit/{gjid}', [UserController::class, 'update'])->name('user-update');

0 comments on commit e5a523d

Please sign in to comment.