0
votes

I am getting the error below even though my Controller class is present in my Controllers directory;

Fatal error: Class 'App\Http\Controllers\Controller' not found

Below is the content of my UserController controller (in the same directory, Controllers):

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function SignIn(Request $request)
    {
        if (Auth::attempt(['usernameEmail'=>$request['usernameEmail'],'password'=>$request['password']])) {
            return redirect()->route('dashboard');
        }
        return redirect()->back();
    }

    public function getDashBoard()
    {
        return view('dashboard');
    }
}

What am I doing wrong and how can I resolve it?

2
try composer dump-autoload and try agin - Md. Abu Taleb
Btw, you're in the same namespace, so you don't need to specify the use statement. - Treast
tried composer dump-autoload but still getting the same error. - K142084 Arsalan Mehmood
Removing the 'use' statement did not help either @Treast - K142084 Arsalan Mehmood
I didn't say it gonna resolve your problem, just clean a little your code. - Treast

2 Answers

0
votes

It you ran composer dump-autoload and it didn't fixed your problem you placed your controller in wrong folder. It should be inside app\Http\Controllers dir.

If it won't fix your issue, look at storage\logs\laravel.log where you can find more informations about the problem, and where your problem occured. Maybe you are defining routes using wrong classname or something like that.

0
votes

You get the Fatal error: Class 'App\Http\Controllers\Controller' not found error because you have no such a class in your project at the derived location.

Instead of

use App\Http\Controllers\Controller; // this is irrelevant and causing the error you get

you should have

use Illuminate\Http\Request; // this is necessary for your SingIn method

as in:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
{
    // your methods here
}

because one of your SignIn method does make use of it.