Laravel 5 - FatalErrorException: Class 'User' not found

composer-php, laravel-5, php

Solution

try to use

`$user = new \App\User;`

instead

`$user = new User;`

Problem

I am very new to Laravel and just started setting up things with Laravel 5. I am attempting to create a simple user authentication app with Laravel. I created register.blade.php which includes form to register user. Here is my routes.php ``` Route::post('/register', function() { $user = new User; $user->email = Input::get('email'); $user->username = Input::get('username'); $user->password = Hash::make(Input::get('password')); $user->save(); $theEmail = Input::get('email'); return View::make('thanks')->with('theEmail', $theEmail); }); ``` Here is the section of register.blade.php which creates form for the user registration. ``` {!! Form::open(array('url' => 'register')) !!} {!! Form::label('email', 'Email Address') !!} {!! Form::text('email') !!} {!! Form::label('username', 'Username') !!} {!! Form::text('username') !!} {!! Form::label('password', 'Password') !!} {!! Form::password('password') !!} {!! Form::submit('Sign Up') !!} {!! Form::close() !!} ``` I am getting this error when I click on Sign Up button on register page. in routes.php line 30 at HandleExceptions->fatalExceptionFromError(array('type' => '1', 'message' => 'Class 'User' not found', 'file' => 'C:\xampp\htdocs\urlshort\app\Http\routes.php', 'line' => '30')) in HandleExceptions.php line 116 at HandleExceptions->handleShutdown() After going through few queries in Google, I realized I forgot to load the User class. So, I included link to file with User class in composer.json file ``` "autoload": { "classmap": [ "database", "app/User.php" ], "psr-4": { "App\\": "app/" } }, ``` I ran the `composer dump-autoload` command. But I am still getting the same error. I am unable to figure out where my code went work.

Original source