Laravel 5.4 PHP 5.6 XAMPP localhost
我已经设置了一个基本的laravel应用程序,我运行了命令:
php artisan make:auth
创建auth脚手架
然后运行命令
php artisan migrate
更新数据库并创建必要的表
我可以注册用户,登录并注销。 但是,其他任何认证都不起作用。
这是我尝试时收到的错误 本地主机/密码/电子邮件
(1/1) MethodNotAllowedHttpException
in RouteCollection.php (line 251)
at RouteCollection->methodNotAllowed(array('POST'))
in RouteCollection.php (line 238)
at RouteCollection->getRouteForMethods(object(Request), array('POST'))
in RouteCollection.php (line 176)
at RouteCollection->match(object(Request))
in Router.php (line 546)
at Router->findRoute(object(Request))
in Router.php (line 525)
at Router->dispatchToRoute(object(Request))
in Router.php (line 511)
at Router->dispatch(object(Request))
in Kernel.php (line 176)
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
in Pipeline.php (line 30)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in TransformsRequest.php (line 30)
at TransformsRequest->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in ValidatePostSize.php (line 27)
at ValidatePostSize->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in CheckForMaintenanceMode.php (line 46)
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
in Pipeline.php (line 148)
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
in Pipeline.php (line 53)
at Pipeline->Illuminate\Routing\{closure}(object(Request))
in Pipeline.php (line 102)
at Pipeline->then(object(Closure))
in Kernel.php (line 151)
at Kernel->sendRequestThroughRouter(object(Request))
in Kernel.php (line 116)
at Kernel->handle(object(Request))
in index.php (line 54)
但是这个方法不允许对我有意义,因为我的Router.php是这样的:
// Password Reset Routes...
$this->get('password/reset',
'Auth\ForgotPasswordController@showLinkRequestForm')-
>name('password.request');
$this->post('password/email',
'Auth\ForgotPasswordController@sendResetLinkEmail')-
>name('password.email');
$this->get('password/reset/{token}',
'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');
我的email.blade.php
...
<form class="form-horizontal" method="POST" action="{{
route('password.email') }}">
{{ csrf_field() }}
...
注意方法=&#34; POST&#34;
我的web.php有&#34; Auth:routes();&#34;
有人可以帮忙吗?
在线文档听起来好像在运行php artisan make:auth是您正确认证流程所需的全部内容,但如果您的用户忘记了密码该怎么办?
另一件事,laravel文档写道: 要开始使用,请验证您的App \ User模型是否实现了 照亮\合同\ Auth \ CanResetPassword合同。
这是我的模型User.php
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
class User extends Authenticatable
{
use Notifiable;
use CanResetPassword;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
}
答案 0 :(得分:0)
当你&#34;尝试&#34; localhost/password/email
您正在使用GET调用URL。此路由(/password/email
)已在router.php
中注册为POST路由,这就是您收到错误的原因。
重置密码的网址应为/password/reset
。
另一件事,laravel文档说:要开始,请验证您的App \ User模型是否实现了Illuminate \ Contracts \ Auth \ CanResetPassword合同。