forked from summerblue/larabbs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7590678
commit c84cc3a
Showing
6 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Auth; | ||
|
||
class UserRequest extends FormRequest | ||
{ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
public function rules() | ||
{ | ||
return [ | ||
'name' => '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' => '用户名不能为空。', | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
database/migrations/2019_09_19_185528_add_avatar_and_introduction_to_users_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class AddAvatarAndIntroductionToUsersTable extends Migration | ||
{ | ||
public function up() | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->string('avatar')->nullable(); | ||
$table->string('introduction')->nullable(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dropColumn('avatar'); | ||
$table->dropColumn('introduction'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@if (count($errors) > 0) | ||
<div class="alert alert-danger"> | ||
<div class="mt-2"><b>有错误发生:</b></div> | ||
<ul class="mt-2 mb-2"> | ||
@foreach ($errors->all() as $error) | ||
<li><i class="glyphicon glyphicon-remove"></i> {{ $error }}</li> | ||
@endforeach | ||
</ul> | ||
</div> | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@extends('layouts.app') | ||
|
||
@section('content') | ||
|
||
<div class="container"> | ||
<div class="col-md-8 offset-md-2"> | ||
|
||
<div class="card"> | ||
<div class="card-header"> | ||
<h4> | ||
<i class="glyphicon glyphicon-edit"></i> 编辑个人资料 | ||
</h4> | ||
</div> | ||
|
||
<div class="card-body"> | ||
|
||
<form action="{{ route('users.update', $user->id) }}" method="POST" accept-charset="UTF-8"> | ||
<input type="hidden" name="_method" value="PUT"> | ||
<input type="hidden" name="_token" value="{{ csrf_token() }}"> | ||
|
||
@include('shared._error') | ||
|
||
<div class="form-group"> | ||
<label for="name-field">用户名</label> | ||
<input class="form-control" type="text" name="name" id="name-field" value="{{ old('name', $user->name) }}" /> | ||
</div> | ||
<div class="form-group"> | ||
<label for="email-field">邮 箱</label> | ||
<input class="form-control" type="text" name="email" id="email-field" value="{{ old('email', $user->email) }}" /> | ||
</div> | ||
<div class="form-group"> | ||
<label for="introduction-field">个人简介</label> | ||
<textarea name="introduction" id="introduction-field" class="form-control" rows="3">{{ old('introduction', $user->introduction) }}</textarea> | ||
</div> | ||
<div class="well well-sm"> | ||
<button type="submit" class="btn btn-primary">保存</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
@endsection |