Laravel 5.1 nested controller class not found
The Laravel documentation clearly describes how to change routes if you insert your controllers into folders. Seems REALLY simple and yet I still get the error. Here's the error:
"Application class \ Http \ Controllers \ Input \ InputController does not exist"
^ This path looks 100% correct to me. What gives?
The structure of the file:
-Controllers
--auth
--input
--- InputController.php
Routes
Route::get('input', 'Input\InputController@getInput');
InputController:
<?php namespace App\Http\Controllers;
use Illuminate\Http\Response;
class InputController extends Controller
{
public function getInput()
{
return response()->view('1_input.input_form');
}
}
Thanks for any help!
source to share
you should try running a couple of commands in your base directory from your terminal (shell / prompt):
composer dump-autoload
or if you don't have composer as executable:
php composer dump-autoload
and then:
php artisan clear-compiled
This way your laravel will cook everything again from scratch and should be able to find the missing controller class.
Basically laravel generates some extra files to load faster. If you define a new class, it is not included in this "compiled" file. Thus, your class must be "injected" into the struct.
source to share
- the namespace needs to be changed to the directory where your controller is located in "App \ Http \ Input"
-
You need to pull out the controller using App \ Http \ Controllers \ Contoller so you can extend it.
<?php namespace App\Http\Controllers\Input; use App\Http\Controllers\Controller; // need Controller to extend use Illuminate\Http\Response; class InputController extends Controller { public function getInput() { return response()->view('1_input.input_form'); } }
source to share