Level 41
If your controller is not within the same namespace as the base Controller (and it isn't), you need to add this to the top:
use App\Http\Controllers\Controller;
5 likes
Why am I getting Class 'App\Http\Controllers\Admin\Controller' not found on in AdminController.php line 9?
I have looked at my routes and namespaces and they look ok.
<?php
/*
|--------------------------------------------------------------------------
| Routes File
|--------------------------------------------------------------------------
|
| Here is where you will register all of the routes in an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
|Controls all of the routes that make the admin area work
*/
Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function() {
Route::get('admin','Admin\AdminController@index');
Route::post('/admin/login', 'Admin\AuthController@postLogin');
});
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| This route group applies the "web" middleware group to every route
| it contains. The "web" middleware group is defined in your HTTP
| kernel and includes session state, CSRF protection, and more.
|
*/
Route::group(['middleware' => ['web']], function () {
//
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/admin/dashboard', 'HomeController@index');
});
/*
|--------------------------------------------------------------------------
| Admin Middleware Routes
|--------------------------------------------------------------------------
|Controls all of the routes that make the admin area work
*/
Route::group(['middleware' => 'web'], function (){
Route::auth();
Route::get('/admin','Admin\AdminController@index');
});
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests;
use Illuminate\Http\Request;
class AdminController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the Admin Login Page.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('admin.login');
}
}
If your controller is not within the same namespace as the base Controller (and it isn't), you need to add this to the top:
use App\Http\Controllers\Controller;
Please or to participate in this conversation.