未定义的方法::在laravel中验证

时间:2016-03-03 00:33:39

标签: php laravel laravel-5 laravel-5.1

正在恢复密码,一切正常,因为我添加了一个验证器,但是我收到一个错误:"未定义的方法... \ 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)]);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

除非您使用适当的特征,否则控制器没有验证方法。您无法在validate()上使用$this功能。仅当您在控制器上使用ValidatesRequests特征

时,它才会起作用

就在

之后
class PasswordController{

你必须插入下面的

use ValidateRequests;