From 97d186c5d6f581d799dfb7c8a74d31113200b7e2 Mon Sep 17 00:00:00 2001 From: Wisp X Date: Sun, 13 Feb 2022 17:40:59 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E7=B3=BB=E7=BB=9F=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/Mail/SmtpOption.php | 6 ++ .../Controllers/Admin/SettingController.php | 13 +++- resources/views/admin/setting/index.blade.php | 72 ++++++++++++------- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/app/Enums/Mail/SmtpOption.php b/app/Enums/Mail/SmtpOption.php index f252f658..6fbeb16f 100644 --- a/app/Enums/Mail/SmtpOption.php +++ b/app/Enums/Mail/SmtpOption.php @@ -23,4 +23,10 @@ final class SmtpOption /** @var string 超时时间 */ const Timeout = 'timeout'; + + /** @var string 发件人地址 */ + const FromAddress = 'from_address'; + + /** @var string 发件人名称 */ + const FromName = 'from_name'; } diff --git a/app/Http/Controllers/Admin/SettingController.php b/app/Http/Controllers/Admin/SettingController.php index 62ff2486..a7cf2746 100644 --- a/app/Http/Controllers/Admin/SettingController.php +++ b/app/Http/Controllers/Admin/SettingController.php @@ -3,18 +3,27 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Config; +use App\Utils; +use Illuminate\Http\Request; use Illuminate\Http\Response; +use Illuminate\Support\Facades\Cache; use Illuminate\View\View; class SettingController extends Controller { public function index(): View { - return view('admin.setting.index'); + $configs = Utils::config(); + return view('admin.setting.index', compact('configs')); } - public function save(): Response + public function save(Request $request): Response { + foreach ($request->all() as $key => $value) { + Config::query()->where('name', $key)->update(['value' => $value]); + } + Cache::flush(); return $this->success('保存成功'); } } diff --git a/resources/views/admin/setting/index.blade.php b/resources/views/admin/setting/index.blade.php index 6b6e8c95..5cc9abef 100644 --- a/resources/views/admin/setting/index.blade.php +++ b/resources/views/admin/setting/index.blade.php @@ -7,19 +7,19 @@
- +
- + {{ $configs['site_keywords'] }}
- + {{ $configs['site_description'] }}
- +
@@ -33,16 +33,20 @@
- + + - + + - + + - + +
@@ -56,7 +60,7 @@
- +
@@ -66,46 +70,55 @@

邮件配置

-
-
- - SMTP - +
+ + SMTP + - - +
@push('scripts') @@ -122,6 +135,13 @@ $('[data-select]').click(function () { setSelected(); }); + + $('form').submit(function (e) { + e.preventDefault(); + axios.put(this.action, $(this).serialize()).then(function (response) { + toastr[response.data.status ? 'success' : 'error'](response.data.message) + }); + }); @endpush