Misc.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Classes\Settings;
  3. use App\Models\Settings;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Facades\Validator;
  7. class Misc
  8. {
  9. public function __construct()
  10. {
  11. return;
  12. }
  13. public function updateSettings(Request $request)
  14. {
  15. $validator = Validator::make($request->all(), [
  16. 'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
  17. 'favicon' => 'nullable|max:10000|mimes:ico',
  18. 'discord-bot-token' => 'nullable|string',
  19. 'discord-client-id' => 'nullable|string',
  20. 'discord-client-secret' => 'nullable|string',
  21. 'discord-guild-id' => 'nullable|string',
  22. 'discord-invite-url' => 'nullable|string',
  23. 'discord-role-id' => 'nullable|string',
  24. 'recaptcha-site-key' => 'nullable|string',
  25. 'recaptcha-secret-key' => 'nullable|string',
  26. 'enable-recaptcha' => 'nullable|string',
  27. 'mailservice' => 'nullable|string',
  28. 'mailhost' => 'nullable|string',
  29. 'mailport' => 'nullable|string',
  30. 'mailusername' => 'nullable|string',
  31. 'mailpassword' => 'nullable|string',
  32. 'mailencryption' => 'nullable|string',
  33. 'mailfromadress' => 'nullable|string',
  34. 'mailfromname' => 'nullable|string',
  35. 'enable_referral' => 'nullable|string',
  36. 'referral_reward' => 'nullable|numeric',
  37. 'referral_allowed' => 'nullable|string',
  38. ]);
  39. if ($validator->fails()) {
  40. return redirect(route('admin.settings.index') . '#misc')->with('error', __('Misc settings have not been updated!'))->withErrors($validator)
  41. ->withInput();
  42. }
  43. if ($request->hasFile('icon')) {
  44. $request->file('icon')->storeAs('public', 'icon.png');
  45. }
  46. if ($request->hasFile('favicon')) {
  47. $request->file('favicon')->storeAs('public', 'favicon.ico');
  48. }
  49. $values = [
  50. "SETTINGS::DISCORD:BOT_TOKEN" => "discord-bot-token",
  51. "SETTINGS::DISCORD:CLIENT_ID" => "discord-client-id",
  52. "SETTINGS::DISCORD:CLIENT_SECRET" => "discord-client-secret",
  53. "SETTINGS::DISCORD:GUILD_ID" => "discord-guild-id",
  54. "SETTINGS::DISCORD:INVITE_URL" => "discord-invite-url",
  55. "SETTINGS::DISCORD:ROLE_ID" => "discord-role-id",
  56. "SETTINGS::RECAPTCHA:SITE_KEY" => "recaptcha-site-key",
  57. "SETTINGS::RECAPTCHA:SECRET_KEY" => "recaptcha-secret-key",
  58. "SETTINGS::RECAPTCHA:ENABLED" => "enable-recaptcha",
  59. "SETTINGS::MAIL:MAILER" => "mailservice",
  60. "SETTINGS::MAIL:HOST" => "mailhost",
  61. "SETTINGS::MAIL:PORT" => "mailport",
  62. "SETTINGS::MAIL:USERNAME" => "mailusername",
  63. "SETTINGS::MAIL:PASSWORD" => "mailpassword",
  64. "SETTINGS::MAIL:ENCRYPTION" => "mailencryption",
  65. "SETTINGS::MAIL:FROM_ADDRESS" => "mailfromadress",
  66. "SETTINGS::MAIL:FROM_NAME" => "mailfromname",
  67. "SETTINGS::REFERRAL::ENABLED" => "enable_referral",
  68. "SETTINGS::REFERRAL::REWARD" => "referral_reward",
  69. "SETTINGS::REFERRAL::ALLOWED" => "referral_allowed"
  70. ];
  71. foreach ($values as $key => $value) {
  72. $param = $request->get($value);
  73. Settings::where('key', $key)->updateOrCreate(['key' => $key], ['value' => $param]);
  74. Cache::forget("setting" . ':' . $key);
  75. }
  76. return redirect(route('admin.settings.index') . '#misc')->with('success', __('Misc settings updated!'));
  77. }
  78. }