Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting

ErrorException in AccountController.php line 47:
Undefined variable: user

Here's my account controller code

PHP
<?php
namespace App\Http\Controllers;
use Input;
use Illuminate\Support\Facades\Redirect;
use App\User;
use Hash;
class AccountController extends Controller {
    
    public function getCreate(){
        
     return \View::make('account.create');   
    }
    
    public function postCreate(){
        
        $validator= \Validator::make(input::all(),
        array(
            'email'=>'required|max:50|email|unique:users',
            'username'=>'required|max:20|min:3|unique:users',
            'password'=>'required|min:6',
            'password_again'=>'required|same:password'
            ));
            
            if($validator->fails()){
                
                return Redirect::route('account-create')
                       ->withErrors($validator)
                       ->withInput();
                
            }else{
                
                //create account
                
                $email = Input::get('email');
                $username = Input::get('username');
                $password = Input::get('password');
                //Activation code
                $code=str_random(60);
                
                $create = User::create(array(
                    'email'=>$email,
                    'username'=>$username,
                    'password'=>Hash::make($password),
                    'code'=>$code,
                    'active'=>0
                    ));
                    if($user){
                        return Redirect::route('home')
                        ->with('global',"sent email");
                        
                        
                    }
                    }
                
            }
        
        
    }
Posted
Comments
ankur1163 13-Dec-15 9:39am    
Can someone tell me whats the error here?
Kornfeld Eliyahu Peter 13-Dec-15 9:52am    
Which is line 47?

1 solution

The error is at this line:
PHP
if($user){

You are using the $user variable, but there is no $user variable created yet. That's the reason you get the error. To solve this, you have to create $user the way you want. (Or replace it by another variable name if that's what you intended to do. It looks like you might have meant to put $create there, but I cannot know that for sure).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Dec-15 11:37am    
5ed.
—SA
Thomas Daniels 13-Dec-15 12:25pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900