This commit is contained in:
root 2019-10-27 21:41:33 +08:00
parent ae3b9b7c30
commit 87ae0403e7
2 changed files with 49 additions and 0 deletions

View File

@ -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
]);
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserUpdate extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'remind_expire' => 'in:0,1',
'remind_traffic' => 'in:0,1'
];
}
public function messages()
{
return [
'show.in' => '过期提醒格式不正确',
'renew.in' => '流量提醒格式不正确'
];
}
}