Support the ongoing development of Laravel.io →
Database Validation Mail

Hi, I have this function for password recovery

	
public function postForgotPassword()
    {
        $validator = Validator::make(Input::all(), array(
            'email' => 'required|email'
        ));
        if($validator->fails())
        {
            return Redirect::route('account-forgot-password')
                ->withErrors($validator)
                ->withInput();
        }
        else
        {
            $user = User::where('email', '=', Input::get('email'));

            if($user->count())
            {
                $user                  = $user->first();
                $code                  = str_random(60);
                $password              = str_random(10);
                $user->$code           = $code;
                $user->$password_temp  = Hash::make($password);

                if($user->save())
                {
                    Mail::send('emails.auth.forgot', array('link' => URL::route('account-recover', $code), 'username' =>$user->username, 'password' => $password), function($message) use($user){
                         $message ->to($user->email, $user->username)->subject('Your new password');
                    });
                    return Redirect::route('home')
                            ->with('global','We have sent you new password');
                }

            }
        }
        return Redirect::route('account-forgot-password')
                ->with('global', "Could not request new password");

    }	

But when I try to recover I get the error - ErrorException (E_UNKNOWN) Undefined variable: password_temp? $password_temp is valid row from table users..

Last updated 3 years ago.
0

You need to get rid of your $,

You are trying to render a variable called $password_temp, which would work if the value was a field name but that isn't what you want.... What you want is to access a field named password_temp.

Change this

$user->$code           = $code;
$user->$password_temp  = Hash::make($password);

To this

$user->code           = $code;
$user->password_temp  = Hash::make($password);
Last updated 3 years ago.
0

Well, now is working. Thank you for your help!

Last updated 3 years ago.
0

You might also want to validate if the email exists

'email' => 'required|email|exists:table,column'
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

vinsbg vinsbg Joined 26 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.