使用laravel的登录脚手架

 Laravel      阅读(41)   2019-09-13 23:12:42 

 安装laravel框架

composer create-project laravel/laravel larabbs --prefer-dist "5.8.*"

使用命令创建auth

php artisan make:auth

加入路由

// 用户身份验证相关的路由
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login', 'Auth\LoginController@login');
Route::post('logout', 'Auth\LoginController@logout')->name('logout');

// 用户注册相关路由
Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController@register');

// 密码重置相关路由
Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');

// Email 认证相关路由
Route::get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');

Auth::routes(); //等价于上面

配置中文包

composer require "overtrue/laravel-lang:~3.0"
在 config目录下的app.php配置中修改'locale' => 'zh-CN','timezone' => 'Asia/Shanghai',
providers数组中 Illuminate\Translation\TranslationServiceProvider::class, 替换为

Overtrue\LaravelLang\TranslationServiceProvider::class,

执行命令php artisan migrate

再次修改auth中=“/home”为/ 模板中可以使用@guest @else @@endguest检测登录以及登录显示的板块

{{ Auth::user()->name }} 获取登录的用户名

加入验证码

composer require "mews/captcha:~2.0"
php artisan vendor:publish --provider='Mews\Captcha\CaptchaServiceProvider'

app/Http/Controllers/Auth/RegisterController.php中修改

protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:6', 'confirmed'],
'captcha' => ['required', 'captcha'],
], [
'captcha.required' => '验证码不能为空',
'captcha.captcha' => '请输入正确的验证码',
]);
}

配置邮箱后。可以拥有登录,注册,找回验证码。等功能!





我要评论



展示评论