13

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.

1
  • Have the same isssue can U help ? Commented Feb 19, 2019 at 5:57

3 Answers 3

26

try to use

$user = new \App\User;

instead

$user = new User;

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

2 Comments

Only if the User class is in a namespace. If it is he can remove "app/User.php" from his composer.json
Because he use l5. I think he use default User.php it in namespace App, may be.
1

I had the same issue, the answer above didn't help, but I used

use App\Models\Access\User\User; instead of use User; in my controller and it worked.

Comments

1

Type App\Models\User it worked for me

Comments

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.