3

The Laravel documentation clearly describes how to change your routes if you nest your controllers in folders. It seems REALLY simple, and yet I'm still getting an error. Here's the error:

"Class App\Http\Controllers\Input\InputController does not exist"

^That path looks 100% correct to me. What gives?

File Structure:
-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!

3 Answers 3

3

Change Controller namespace from

namespace App\Http\Controllers

to

namespace App\Http\Controllers\Input
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! In addition, I also added the line "use App\Http\Controllers\Controller"
1
  1. namespace needs to be changed to the directory your controller is in 'App\Http\Input'
  2. You need to pull in Controller with use App\Http\Controllers\Contoller so that 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');
         }
     }
    

Comments

0

you should try running a couple commands in your base dir from your terminal (shell/prompt):

composer dump-autoload

or if you don't have composer set as executable:

php composer dump-autoload

and then:

php artisan clear-compiled

This way your laravel would prepare everything again "from scratch" and should be able to find the missing controller class.

Basically laravel generates some additional files to boot up faster. If you define a new class it doesn't get included into that "compiled" file. This way your class should be "introduced" to the framework.

Comments

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.