简体   繁体   中英

Fatal Error Class 'App\Http\Controllers\Controller' not found Laravel 5.4

I tried to route with using name .

I already tried to solve with using Composer update , Clear Cache , Generate App key.

But it's showing fatal error .

Error View Message :

(1/1) FatalErrorException
Class 'App\Http\Controllers\Controller' not found
in ClassesController.php line 13

My Route Code Below :

<?php
  Route::prefix('Classes')->group(function(){
  Route::get('/add','ClassesController@index')->name('AddNewClass');
});

My Controller Code Below :

<?php
  namespace App\Http\Controllers;

  use App\Http\Controllers\Controller;

  use Illuminate\Http\Request;



  class ClassesController extends Controller{
    public function index()
     {
       return "Method Access";
     }

In this event, I would first ensure that the file containing the class Controller exists in the same directory with the same namespace as the ClassesController , as implied in your code.

If the Controller does not exist, you can either create the class or simply remove the extends Controller and the line use App\\Http\\Controllers\\Controller; from your code.

its worked for me. usercontroller

<?php

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;


class UserController extends Controller
{
    /**
     * Show the profile for the given user.
     */

    /* http://localhost:8080/laravelapps/blog/public/staff */
    public function showProfile()
    {
       return 'new';
    }
}

web.php

Route::get('/staff', 'UserController@showProfile');

http://localhost:8080/laravelapps/blog/public/staff

  • Check whether Controller.php file exists or not in your Controllers folder if not exists download or put from laravel project.
  • After that run following command php artisan app:name newproject
  • Make sure in the above line i have updated text 'newproject' that should be first line of your Controller.php file. For example: namespace newproject\\Http\\Controllers;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM