I've found many posts regarding putting controllers in sub folders, Most if not all seem to be related to namespace or naming issues. I just cant seem to get it working, and keep getting the following ReflectionException and FatalError Reporting the class is in use.
[2016-12-22 16:51:13] local.ERROR: ReflectionException: Class App\Http\Controllers\Admin\DashboardController does not exist in /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Container/Container.php(749): ReflectionClass->__construct('App\\Http\\Contro...')
#1 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('App\\Http\\Contro...', Array)
#2 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('App\\Http\\Contro...', Array)
#3 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Foundation\Application->make('App\\Http\\Contro...')
#4 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Route.php(316): Illuminate\Routing\Route->getController()
#5 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Route.php(278): Illuminate\Routing\Route->controllerMiddleware()
#6 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Router.php(655): Illuminate\Routing\Route->gatherMiddleware()
#7 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\Routing\Router->gatherRouteMiddleware(Object(Illuminate\Routing\Route))
#8 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Router.php(618): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#9 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Router.php(596): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#10 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(267): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#12 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#13 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(137): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#14 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(33): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#16 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(149): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#17 /vagrant/myApp/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#18 /vagrant/myApp/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#19 {main}
[2016-12-22 16:51:13] local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Cannot declare class App\Http\Controller\Admin\DashboardController, because the name is already in use in /vagrant/myApp/app/Http/Controllers/Admin/DashboardController.php:0
Stack trace:
#0 {main}
I have tried using different class names, that didn't solve anything. As long as I route to a controller in the Admin folder/namespace I get the listed error. I have ran composer dump-autoload
after every change and ran php artisan cache:clear
just to be safe
My Folder Structure
/app/
Console/
Exceptions/
Http/
Controllers/
Admin/
DashboardController.php
Auth/
Controller.php
...OtherController.php files live here in the base Controller folder
Middleware/
Providers/
/routes/web.php
...
// Admin Routes
Route::group( [ 'namespace' => 'Admin','prefix' => 'admin' ], function(){
Route::get( '/', 'DashboardController@showAdminHome' )->name( 'admin.dashboard' );
});
/app/Http/Controllers/Admin/DashboardController.php
<?php
namespace App\Http\Controller\Admin;
use App\Http\Controllers\Controller;
class DashboardController extends Controller {
public function showAdminHome() {
return view( 'admin.dashboard' );
}
} //- END Admin\DashboardController{}
I've ran out of things to try and appreciate any help.
s
to pluralizeControllers
– Eric Tucker