diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index e2cc3fe7..b993efda 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Http\Requests\UserUpdate; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\User; @@ -120,4 +121,23 @@ class UserController extends Controller 'data' => true ]); } + + public function update (UserUpdate $request) { + $updateData = $request->only([ + 'remind_expire', + 'remind_traffic' + ]); + + $user = User::find($request->session()->get('id')); + if (!$user) { + abort(500, '该用户不存在'); + } + if (!$user->update($updateData)) { + abort(500, '保存失败'); + } + + return response([ + 'data' => true + ]); + } } diff --git a/app/Http/Requests/UserUpdate.php b/app/Http/Requests/UserUpdate.php new file mode 100644 index 00000000..e97cbeca --- /dev/null +++ b/app/Http/Requests/UserUpdate.php @@ -0,0 +1,29 @@ + 'in:0,1', + 'remind_traffic' => 'in:0,1' + ]; + } + + public function messages() + { + return [ + 'show.in' => '过期提醒格式不正确', + 'renew.in' => '流量提醒格式不正确' + ]; + } +}