PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 9, 2022

[FIXED] Laravel 5 - FatalErrorException: Class 'User' not found

 February 09, 2022     composer-php, laravel-5, php     No comments   

Issue

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.


Solution

try to use

$user = new \App\User;

instead

$user = new User;



Answered By - xcerx
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing