LeaveController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers\Account;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Traits\CommonTrait;
  6. use App\Models\User;
  7. class LeaveController extends Controller
  8. {
  9. use CommonTrait;
  10. private User $userModel;
  11. public function __construct(User $user)
  12. {
  13. $this->middleware(['front', 'auth']);
  14. $this->userModel = $user;
  15. }
  16. /**
  17. * 회원탈퇴
  18. * @method GET
  19. * @see /account/leave
  20. */
  21. public function index()
  22. {
  23. return view(layout('account.leave'), [
  24. 'user' => $this->userModel->info(),
  25. 'menuID' => 'LEAVE'
  26. ]);
  27. }
  28. /**
  29. * 회원 탈퇴 처리
  30. * @method POST
  31. * @see /account/leave/update
  32. */
  33. public function update(Request $request)
  34. {
  35. $rules = [
  36. 'password' => 'required|confirmed',
  37. 'withdrawal' => 'required|in:0,1'
  38. ];
  39. $attributes = [
  40. 'password' => '비밀번호',
  41. 'password_confirmation' => '비밀번호 확인',
  42. 'withdrawal' => '안내 동의'
  43. ];
  44. $posts = $this->validate($request, $rules, [], $attributes);
  45. // 비밀번호 확인
  46. $certified = $this->passwordAuthed($posts['password']);
  47. if(!$certified) {
  48. return back()->withErrors('비밀번호가 일치하지 않습니다.');
  49. }
  50. $user = $request->user();
  51. $user->is_withdraw = 1;
  52. $user->deleted_at = now();
  53. $user->save();
  54. return redirect()->route('logout')->with('message', '회원탈퇴가 완료되었습니다.');
  55. }
  56. }