surgiie surgiie - 5 months ago 19
PHP Question

Laravel 5 Namespace issue fatal error exception

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 im not sure why im getting this error. Am i name spacing wrong?

Answer

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/