NotifyController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Admin\Config\Setting;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Config;
  6. class NotifyController extends Controller
  7. {
  8. private Config $configModel;
  9. public function __construct(Config $config)
  10. {
  11. $this->configModel = $config;
  12. }
  13. /**
  14. * 알림
  15. * @method GET
  16. * @see /admin/config/setting/notify
  17. */
  18. public function index()
  19. {
  20. return view('admin.config.setting.notify', []);
  21. }
  22. /**
  23. * 알림 저장
  24. * @method POST
  25. * @see /admin/config/setting/notify
  26. */
  27. public function store(Request $request)
  28. {
  29. $rules = [
  30. 'use_notification' => 'numeric|nullable|in:0,1',
  31. 'notification_post_reply' => 'numeric|nullable|in:0,1',
  32. 'notification_post_comment' => 'numeric|nullable|in:0,1',
  33. 'notification_post_comment_reply' => 'numeric|nullable|in:0,1'
  34. ];
  35. $attributes = [
  36. 'use_notification' => '알림 기능',
  37. 'notification_post_reply' => '내 글에 답변글이 달렸을 때 알림',
  38. 'notification_post_comment' => '내 글에 댓글이 달렸을 때 알림',
  39. 'notification_post_comment_reply' => '내 댓글에 댓글이 달렸을 때 알림'
  40. ];
  41. $posts = $this->validate($request, $rules, [], $attributes);
  42. $posts['use_notification'] ??= '0';
  43. $posts['notification_post_reply'] ??= '0';
  44. $posts['notification_post_comment'] ??= '0';
  45. $posts['notification_post_comment_reply'] ??= '0';
  46. $this->configModel->save($posts, $attributes);
  47. $message = '알림 정보가 저장되었습니다.';
  48. return redirect()->route('admin.config.setting.notify.index')->with('message', $message);
  49. }
  50. }