1.本节需要发送验证邮件

2.教程使用SendCloud发送邮件 【我使用的是mailtrap】

3.

  1 composer require laravel/ui

安装完成后

  1 php artisan ui vue –auth

4.RegisterController中create方法内实现用户创建的默认值配置

  1 class RegisterController extends Controller
2 {
3 /*
4 |--------------------------------------------------------------------------
5 | Register Controller
6 |--------------------------------------------------------------------------
7 |
8 | This controller handles the registration of new users as well as their
9 | validation and creation. By default this controller uses a trait to
10 | provide this functionality without requiring any additional code.
11 |
12 */
13
14 use RegistersUsers;
15
16 /**
17 * Where to redirect users after registration.
18 *
19 * @var string
20 */
21 protected $redirectTo = RouteServiceProvider::HOME;
22
23 /**
24 * Create a new controller instance.
25 *
26 * @return void
27 */
28 public function __construct()
29 {
30 $this->middleware('guest');
31 }
32
33 /**
34 * Get a validator for an incoming registration request.
35 *
36 * @param array $data
37 * @return \Illuminate\Contracts\Validation\Validator
38 */
39 protected function validator(array $data)
40 {
41 return Validator::make($data, [
42 'name' => ['required', 'string', 'max:255'],
43 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
44 'password' => ['required', 'string', 'min:8', 'confirmed'],
45 ]);
46 }
47
48 /**
49 * Create a new user instance after a valid registration.
50 *
51 * @param array $data
52 * @return \App\User
53 */
54 protected function create(array $data)
55 {
56 return User::create([
57 'name' => $data['name'],
58 'email' => $data['email'],
59 'avatar' => '/image/avatars/default.png',
60 //这里其实不需要再设置activation_token的值,也不需要再在验证后设置activated=1 采用Laravel提供的新功能验证用户邮箱即可 默认带一个email_verified_at字段,且更加完善具有过期时间戳和签名
61 'activation_token' => str_random(),//通过composer require laravel/helpers安装扩展包
62 'password' => Hash::make($data['password']),
63 ]);
64 }
65 }
66

注意:去掉教程当中发送邮件部分的代码,直接使用默认的Laravel提供的邮件验证流程 User.php实现MustVerifyEmail及verify的添加:如下三个文件内部的代码

User.app中:

  1 class User extends Authenticatable implements MustVerifyEmail
2 {
3 use Notifiable;
4
5 /**
6 * The attributes that are mass assignable.
7 *
8 * @var array
9 */
10 protected $fillable = [
11 'name', 'email', 'password', 'avatar', 'activation_token'
12 ];
13
14 /**
15 * The attributes that should be hidden for arrays.
16 *
17 * @var array
18 */
19 protected $hidden = [
20 'password', 'remember_token',
21 ];
22
23 /**
24 * The attributes that should be cast to native types.
25 *
26 * @var array
27 */
28 protected $casts = [
29 'email_verified_at' => 'datetime',
30 ];
31 }

HomeController当中:

  1 class HomeController extends Controller
2 {
3 /**
4 * Create a new controller instance.
5 *
6 * @return void
7 */
8 public function __construct()
9 {
10 $this->middleware(['auth', 'verified']);
11 }
12
13 /**
14 * Show the application dashboard.
15 *
16 * @return \Illuminate\Contracts\Support\Renderable
17 */
18 public function index()
19 {
20 return view('home');
21 }
22 }

web.php当中:

  1 <?php
2
3 /*
4 |--------------------------------------------------------------------------
5 | Web Routes
6 |--------------------------------------------------------------------------
7 |
8 | Here is where you can register web routes for your application. These
9 | routes are loaded by the RouteServiceProvider within a group which
10 | contains the "web" middleware group. Now create something great!
11 |
12 */
13
14 Route::get('/', function () {
15 return view('welcome');
16 });
17
18 Auth::routes(['verify' => true]);
19
20 Route::get('/home', 'HomeController@index')->name('home');
21

5.要使用helper方法需要 composer require laravel/helpers  安装扩展包

Laravel Vuejs 实战:开发知乎 (2)用户注册的更多相关文章

  1. Laravel Vuejs 实战:开发知乎 (6)发布问题

    1.view部分: 安装一个扩展包:Laravel-UEditor composer require "overtrue/laravel-ueditor:~1.0" 配置 添加下面 ...

  2. Laravel Vuejs 实战:开发知乎 (10)使用 Select2 优化话题选择

    1.添加选择Topic 使用Select2,如何安装Select2 ,具体使用实例 Select2 and Laravel: Ajax Autocomplete 及 Loading data remo ...

  3. Laravel Vuejs 实战:开发知乎 (9)定义话题与问题关系

    1.话题[Topic] 执行命令: php artisan make:model Topic –cmr 修改****_**_**_create_topics_table.php数据库迁移文件如下: c ...

  4. Laravel Vuejs 实战:开发知乎 (8)美化编辑器

    1.使用UEditor增量包: simple-ueditors 执行下载: git clone https://github.com/JellyBool/simple-ueditor.git 2.用此 ...

  5. Laravel Vuejs 实战:开发知乎 (3)本地化和自定义消息

    1.本地化 由于所有blade默认采用的是 _('')方式输出标签文本,所以可以安装一个语言包,直接指定本地语言为zh_CN即可: 安装 https://github.com/caouecs/Lara ...

  6. Laravel Vuejs 实战:开发知乎 (2)用户登录

    1.安装一个给用户提示的扩展包: 二选一: https://github.com/laracasts/flash [我选的这个]https://github.com/oanhnn/laravel-fl ...

  7. Laravel Vuejs 实战:开发知乎 (1)项目环境配置和用户表设计

    1.使用laragon新建laravel项目 zhihu 2.配置env文件的database设置 DB_DATABASE=zhihu 3.分析users表需要的字段 4.修改数据库迁移文件: cla ...

  8. Laravel Vuejs 实战:开发知乎 (5)设计问题表

    1.执行命令: php artisan make:model Models/Question -cm 2.设计问题的数据库迁移文件中的字段: <?php use Illuminate\Datab ...

  9. Laravel Vuejs 实战:开发知乎 (7)验证问题表单字段

    上一节代码中已经实现 下面代码中的validate内部配置就是: public function store(Request $request) { // $data = $request->v ...

随机推荐

  1. AM335X的应用程序自启动流程以及U盘更新应用程序记录

    在AM335X的SD卡更新系统学习记录中最后更新完系统后,以后运行应用程序都会从EMMC中取出Linux系统运行.接着介绍Linux系统是怎么自己启动我们编写的应用程序的. 1.在AM335X的SD卡 ...

  2. Mysql5.6基础命令

    Centos7下mysql5.6数据库的操作 Mysql如何修改密码? 1.使用mysqladmin修改,这种修改方式需要知道mysql的原始密码 修改密码后我们测试下看看能不能登录成功 怎么才能不需 ...

  3. Redis Distributed lock

    using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using ...

  4. vscode中vim插件对ctrl键的设置

    vim配置 在使用中经常想使用ctrl-c,虽然在vscode中有配置选项可以让vim与ctrl键解绑,但是这样就使用不了vim的VISUAL BLOCK.所以进行了自定义设置. 设置 - Vim C ...

  5. 阻塞队列BlockingQueue之LinkedBlokingQueue

    1.简介 LinkedBlokingQueue 是链表实现的有界阻塞队列,此队列的默认和最大长度为 Integer.MAX_VALUE.此队列按照先进先出的原则对元素进行排序.ArrayList和Ar ...

  6. Andriod正式打包、以及升级应用 重新打包 修改应用名称、应用图 标、应用启动画面

    一,  Android 正式打包.以及升级应用重新打包 1.android studio 把 Flutter 打包成正式包 2.修改应用版本以及升级打包 找到 AndroidManifest.xml ...

  7. 各技能DBC参数

    推荐你  通过 引擎的帮助文件查找标准魔法DB 下面是 部分hero引擎的标准魔法DB 34,解毒术,2,26,16,0,0,0,0,0,2,42,50,44,100,46,200,40,, 35,老 ...

  8. TCL create list from file

    proc create_list {filename {prompt verbose} {opts "" }} { set list_return {} if {[file exi ...

  9. eclipse中引入聚合工程

    一般我们在导入项目的时候都是直接import project, 这对普通java 项目,还是 web 项目,或者是单体的项目都是没有问题的,但是在导入聚合项目的时候这样倒入会使maven的子模块没法被 ...

  10. springMVC 校验时,CustomValidationMessages.properties中的错误提示信息的中文乱码 问题

    今天在学习springmvc的校验时,遇到了CustomValidationMessages.properties配置文件的信息,才错误提示时是乱码的问题:在网上找了很多方法都没解决:最后原来是在配置 ...