Class 'App\Http\Controllers\Controller' not found - Laravel 5.2

37,391

Solution 1

Error can also occur if App/Http/Controllers/ folder does not have Controller.php file.

Make sure file exists.

Solution 2

To make everything correct, run this.

php artisan app:name YourApplicationName 

it is going to change everything with app to your application name, so you wont need to write manually test everywhere

Solution 3

Please correct your namespace in your pagecontroller

<?php


namespace test\Http\Controllers;

use test\Http\Controllers\Controller;

class PagesController extends Controller
{
    public function getAbout(){
         return view('about');   
    }
}

UPDATE :

After change in namespace in controller please dump-autoload your composer:

Composer dump-autoload

Share:
37,391
Ciapss
Author by

Ciapss

Updated on July 09, 2022

Comments

  • Ciapss
    Ciapss almost 2 years

    I am new here but I already checked all solutions about my problem here and still didn't fix it.

    I want to create simple app with tutorial in Laravel 5.2, and I can't make my controller to work.

    I named my app "test" and here is a code:

    PagesController.php:

    <?php
    
    namespace App\Http\Controllers;
    
    use App\Http\Controllers\Controller;
    
    class PagesController extends Controller
    {
        public function getAbout(){
             return view('about');   
        }
    }
    

    routes.php:

    Route::get('about', [
        'as' => 'about',
        'uses' => 'PagesController@getAbout'
    ]);
    

    And Controller.php (default):

    <?php
    
    namespace test\Http\Controllers;
    
    use Illuminate\Foundation\Bus\DispatchesJobs;
    use Illuminate\Routing\Controller as BaseController;
    use Illuminate\Foundation\Validation\ValidatesRequests;
    use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
    
    class Controller extends BaseController
    {
        use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
    }
    

    Do you see any problem here? I am sure all files are in correct folders.

  • Ciapss
    Ciapss about 8 years
    It changed all namespaces, but still has the same error
  • Friendly Code
    Friendly Code over 4 years
    Saved me some time thanks - During package development I copied all my controllers to new package destination (including the default Controller.php file). Once restored all worked OK