diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index c9e9b45b7..ff7b08fb9 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use App\Models\User; +use App\Http\Requests\UserRequest; class UsersController extends Controller { @@ -11,4 +12,15 @@ public function show(User $user) { return view('users.show', compact('user')); } + + public function edit(User $user) + { + return view('users.edit', compact('user')); + } + + public function update(UserRequest $request, User $user) + { + $user->update($request->all()); + return redirect()->route('users.show', $user->id)->with('success', '个人资料更新成功!'); + } } diff --git a/app/Http/Requests/UserRequest.php b/app/Http/Requests/UserRequest.php new file mode 100644 index 000000000..9122f1ad5 --- /dev/null +++ b/app/Http/Requests/UserRequest.php @@ -0,0 +1,33 @@ + 'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,' . Auth::id(), + 'email' => 'required|email', + 'introduction' => 'max:80', + ]; + } + + public function messages() + { + return [ + 'name.unique' => '用户名已被占用,请重新填写', + 'name.regex' => '用户名只支持英文、数字、横杠和下划线。', + 'name.between' => '用户名必须介于 3 - 25 个字符之间。', + 'name.required' => '用户名不能为空。', + ]; + } +} diff --git a/database/migrations/2019_09_19_185528_add_avatar_and_introduction_to_users_table.php b/database/migrations/2019_09_19_185528_add_avatar_and_introduction_to_users_table.php new file mode 100644 index 000000000..ec03880b0 --- /dev/null +++ b/database/migrations/2019_09_19_185528_add_avatar_and_introduction_to_users_table.php @@ -0,0 +1,24 @@ +string('avatar')->nullable(); + $table->string('introduction')->nullable(); + }); + } + + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('avatar'); + $table->dropColumn('introduction'); + }); + } +} diff --git a/resources/views/layouts/_header.blade.php b/resources/views/layouts/_header.blade.php index 4b6a20ed4..b25fc5d6c 100644 --- a/resources/views/layouts/_header.blade.php +++ b/resources/views/layouts/_header.blade.php @@ -27,8 +27,8 @@ {{ Auth::user()->name }}