1

working in recover the password, and everything was working ok since i added a validator, but i get a error: "Undefined method ...\Password\PasswordController::validate"

The function im calling is postEmail

What am i doing wrong?

My code:

<?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
  • Your snippet is a bit messed up at the top so I can't see; does this Controller extend the base controller App\Http\Controllers\Controller? that should have a ValidatesRequests trait. Commented Mar 3, 2016 at 0:48

1 Answer 1

3

A controller doesn't have a validate method unless you use the appropriate traits. You cannot use validate() function on $this. It will be working only if you have the ValidatesRequests trait is used on the controller

so just after

class PasswordController{

you have to insert the below

use ValidateRequests;
Sign up to request clarification or add additional context in comments.

2 Comments

ello, thanks for answering, i just added the use ValidateRequests, that added, but than gave me this error: Trait '...\Api\Controllers\Password\ValidateRequests' not found"
put this at the top use Illuminate\Foundation\Validation\ValidatesRequests;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.