在Laravel 5.2
全新安装中,我正在尝试按照文档获取身份验证功能(注册/登录/注销/等)。以下是我的步骤。
#php artisan make:auth
Created View: /var/www/html/example.com/resources/views/auth/login.blade.php
Created View: /var/www/html/example.com/resources/views/auth/register.blade.php
Created View: /var/www/html/example.com/resources/views/auth/passwords/email.blade.php
Created View: /var/www/html/example.com/resources/views/auth/passwords/reset.blade.php
Created View: /var/www/html/example.com/resources/views/auth/emails/password.blade.php
Created View: /var/www/html/example.com/resources/views/layouts/app.blade.php
Created View: /var/www/html/example.com/resources/views/home.blade.php
Created View: /var/www/html/example.com/resources/views/welcome.blade.php
Installed HomeController.
Updated Routes File.
Authentication scaffolding generated successfully!
#cat app / Http / routes.php
<?php
use Illuminate\Http\Request;
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController@index');
});
#php artisan migrate:install
Migration table created successfully.
#php artisan migrate
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
(我不知道为什么它的日期为“2014”,无论如何。)
在此之后,我已经可以看到在MySQL数据库中创建了以下表格:
[所以我假设数据库连接也正确! ]
[并且正确地出现了带有“登录”“注册”“登录表格”等的主页。 ]
现在,当我去/register
时,已经出现了一个很好的注册表。但是当我填写并提交时,没有任何反应。 (它保持路由回/register
页面,因为什么都没发生。)
然后,当我从Apache Access Logs检查时,请求显示为“GET”。我认为这应该是一个“POST”。我是对的吗?
(错误日志中也没有任何内容)
请发生什么事?
答案 0 :(得分:2)
我自己解决了。
(1)它需要app/Http/Controllers/AuthController.php
中的以下功能:
public function getRegister()
{
return $this->showRegistrationForm();
}
public function postRegister(Request $request)
{
return $this->register($request);
}
(2)在路由器routes.php
文件中,必须在其他功能(在同一中间件组下)之后仅定义函数Route::auth();
。像:
Route::group(['middleware' => 'web'], function () {
Route::get('/home', 'HomeController@index');
Route::auth();
});
(Route::auth();
不能先出现。)
感谢所有人的帮助:)
答案 1 :(得分:1)
尝试删除web
中间件,导致很多人在过去两周内遇到问题(因为Laravel次要更新)。现在web
中间件自动应用于所有路由,当您手动添加它时,会导致不同类型的错误。