0

Im having this fatal error exception that i cant seem to figure out:

Class 'App\Http\Controllers\Admin\Controller' not found

For some reason im not sure why it is tacking controller at the end of that error. My namespace for the controller:

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Announcement;
use App\Http\Requests;

class AnnouncementController extends Controller
{
   ...
}

and my routes:

Route::group(['prefix' => 'admin','namespace'=>'Admin', 'middleware'=>'auth'], function () {


    Route::resource('announcements','AnnouncementController');



});

But when i navigate to the /admin/announcements route i get that fatal exception with the Controller tacked on at the end..

This controller is in the App\Http\Controllers\Admin directory so i m not sure why i m getting this error. Am i name spacing wrong?

5
  • 3
    You extend Controller. There probably isn't a controller class in App\Http\Controllers\Admin Commented Jun 13, 2016 at 3:25
  • Ive tried adding the namespace use App\Http\Controllers\Controller; still no luck :/ AndrewL Commented Jun 13, 2016 at 3:34
  • Use the full qualified class name Commented Jun 13, 2016 at 3:39
  • 1
    try to remove this 'namespace'=>'Admin' and add the use App\Http\Controllers\Controller; Commented Jun 13, 2016 at 3:39
  • 1
    you can leave the 'namespace' => 'Admin' then just refer to the controller in the route as AnnouncementController. Laravel assumes App\Http\Controllers namespace is what you are starting with, based on your RouteServiceProvider. Commented Jun 13, 2016 at 3:58

1 Answer 1

1

Try this

Route

Route::group(['prefix' => 'admin', 'middleware'=>'auth'], function () {

    Route::resource('announcements','Admin\\AnnouncementController');

});

Controller

namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Announcement;
use App\Http\Requests;

class AnnouncementController extends Controller
{
   ...
}

if this dosent work, check if you have a Controller called Controller in app/Http/Controllers/

Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me. Thank you!! It was missing the controller namespace since i created a new directory for Admin controller i needed to use App\Http\Controllers\Controller. Such a obvious mistake... the struggle lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.