Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dokunbam's avatar

"Class App\Http\Controllers\UserController does not exist"

I am a beginner to PHP and laravel I am having this error

This is user controller

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;


class UserController extends Controller
{
    public function postSignUp(Request $request)
    {
        $fullname = $request['fullname'];
        $email    = $request['email'];
        $password = bcrypt($request['password']);
    
        $user = new User();
        $user->fullname = $fullname;
        $user->email    = $email;
        $user->password  = $password;

        $user->save();

        return redirect()->back();

    }
    public function postSignIn()
    {

    }

}
?>

Migration table

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string('fullname');
            $table->string('email');
            $table->string('password');
            $table->rememberToken();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
?>
<?php
@extends('layout.master')

@section('title')
Home
@endsection

@section('content')
<div class="row style=padding-top: 10px;">
        <div class="col-lg-6 col-md-6 col-xs-12">
            <h3 class="text-center text-primary">Register</h3>
            <form action="{{URL('signup')}}" method="post">
                <div class="form-group">
                    <label for="name">Your Full Name</label>
                    <input class="form-control" type="text" name="fullname" id="name">
                </div>

                <div class="form-group">
                    <label for="email">Your Email</label>
                    <input class="form-control" type="email" name="email" id="email">
                </div>

                <div class="form-group">
                    <label for="password">Password</label>
                    <input class="form-control" type="password" name="pass" id="pass">
                </div>

                <div class="form-group">
                    <label for="repeat-pass">Repeat Password</label>
                    <input class="form-control" type="password" name="repeat-pass" id="repeat-pass">
                </div>

                <div class="form-group">
                        <input class="btn btn-primary" type="submit" name="pass" id="pass">
                    </div>
                <input type="hidden" name="_token" value="{{Session::token()}}"
            </form>
                
        </div>
        <div class="col-lg-6 col-md-6 col-xs-12">
            <h3 class="text-center text-danger">Login</h3>
            <form action="" method="post">
                    <div class="form-group">
                        <label for="email">Your Email</label>
                        <input class="form-control" type="email" name="email" id="email">
                    </div>
    
                    <div class="form-group">
                        <label for="password">Password</label>
                        <input class="form-control" type="password" name="pass" id="pass">
                    </div>
    
                    <div class="form-group">
                            <input class="btn btn-danger" type="submit" name="pass" id="pass">
                        </div>
                </form>
                    
    
            </div>

</div>
@endsection
?>

I hope someone can help me out Thanks

0 likes
14 replies
tykus's avatar

Is your UserController.php file located in {PROJECT_ROOT}/app/Http/Controllers/ directory? Have you namespaced your UserController?

<?php

namespace App\Http\Controllers;

class UserController extends Controller
{
    //
}
Shawdow's avatar

I think you need to use only

namespace App\Http\Controllers; 

renoirtech's avatar

A good way to try to fix it fast is stashing the code you already did and creating the basic authentication assets by running the command php artisan make:auth. Then you insert the your custom code inside the classes generated by Laravel.

lostdreamer_nl's avatar

The code seems ok, just a few things you could do (shouldnt remove this error though):

remove all ' ?> ' from the bottom of your PHP files, it's not necessary and it could give problems ( whitespace after the ?> )

And in the view file you dont need the <? php and ? > ither (it's a blade template right?)

I only get this kind of error when there is a big typo in the controller ( extra } for instance) that breaks the script.

What does your route file look like (the part where you link the URL to the controller's method)?

Shawdow's avatar
use Illuminate\Support\Facades\Input;
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;


public function postSignUp(Request $request) {

        $user = new User();
        $user->fullname = Input::get("fullname");
        $user->email    = Input::get("email");
        $user->password  = Input::get("password");
        $user->save();

    return redirect()->back();
}
dokunbam's avatar

@lostdreamer_nl This is my route

Route::group(['middleware' => ['web']], function(){

    Route::get('/', function () {
        return view('home');
    });

    Route::post('/signup', [
        'uses' => 'UserController@postSignUP',
        'as'   => 'postSignUp'
        ]);
});

Snapey's avatar

check the filename and its location.

If you have renamed the file or the class, run composer dump-autoload

dokunbam's avatar

Thanks, everyone, the response here is awesome and super fast. I am happy I can get the quick reply here and everyone is ready to help.

I think its working now, there is a wrong file name.

But when I tried my form I got

The page has expired due to inactivity. 

Please refresh and try again.

I am supposed to be redirected back

tykus's avatar

You need a CSRF token field in your form:

 <form action="{{URL('signup')}}" method="post">
    {{ csrf_field() }}
    //
dokunbam's avatar

Thanks its working now but another error.

Migration worked successfully and I am not using password for DB

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: insert into `users` (`fullname`, `email`, `password`, `updated 

.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:XpZCGtit45zul0//15wWdpzKHa4twAz+CYcO3iVqa4w=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_social
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
shez1983's avatar

you may have to create another user but try "" in the password env...

but the error indicates its using a different USERNAME to that in your env..

if you are using homestead the password is secret.. the username = homestead..

limewater23's avatar
restart the server
php artisan cache:clear; php artisan optimize
php artisan route:list 

Please or to participate in this conversation.