2017.08.09 updated, 增加了动图,修改文字

上一篇文章 Ruby 程序员学习 laravel 框架笔记 (4)-在数据库中创建一条数据 有讲过创建一条 user 记录,其实这个相当于注册功能,今天要学习的就是跟这个注册功能有关。

laravel 神奇的一个地方就是默认集成了登录和注册的功能,只要一条指令就可以启动,不仅如此,连 view 都给你写好了,也就是说界面都可以不用写,就有登录和注册的功能。

1. 启用登录注册功能

只要一条指令:

php artisan make:auth

我们来查一下路由,看到底产生了些啥功能:

php artisan route:list

输出如下:

+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
| Domain | Method   | URI                    | Name             | Action                                                                 | Middleware   |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                      |                  | Closure                                                                | web          |
|        | GET|HEAD | api/user               |                  | Closure                                                                | api,auth:api |
|        | GET|HEAD | home                   | home             | App\Http\Controllers\HomeController@index                              | web,auth     |
|        | GET|HEAD | login                  | login            | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    |
|        | POST     | login                  |                  | App\Http\Controllers\Auth\LoginController@login                        | web,guest    |
|        | POST     | logout                 | logout           | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | POST     | password/email         | password.email   | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD | password/reset         | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST     | password/reset         |                  | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    |
|        | GET|HEAD | password/reset/{token} | password.reset   | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | GET|HEAD | register               | register         | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register               |                  | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
|        | GET|HEAD | users                  |                  | App\Http\Controllers\UsersController@index                             | web          |
|        | POST     | users                  |                  | App\Http\Controllers\UsersController@store                             | web          |
|        | GET|HEAD | users/create           |                  | App\Http\Controllers\UsersController@create                            | web          |
+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+

2. 展示功能

现在我们来验证一下这些功能。

打开浏览器,输入 http://127.0.0.1/login

页面是这样子的:

页面还不错。

注册页面也有:

注册完会自动登录,登录后的页面如下:

完结。

下一篇:Ruby 程序员学习 laravel 框架笔记 (6)-修改 User model

results matching ""

    No results matching ""