正在恢复密码,一切正常,因为我添加了一个验证器,但是我收到一个错误:"未定义的方法... \ Password \ PasswordController :: validate"
im调用函数是postEmail
我做错了什么?
我的代码:
<?php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
trait ResetsPasswords
{
use RedirectsUsers;
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
switch ($response) {
case Password::RESET_LINK_SENT:
return redirect()
->back()
->with('status', trans($response));
case Password::INVALID_USER:
return redirect()
->back()
->withErrors(['email' => trans($response)]);
}
}
}
答案 0 :(得分:1)
除非您使用适当的特征,否则控制器没有验证方法。您无法在validate()
上使用$this
功能。仅当您在控制器上使用ValidatesRequests
特征
就在
之后class PasswordController{
你必须插入下面的
use ValidateRequests;