Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 nested controller class not found

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!

like image 691
user3023925 Avatar asked Feb 12 '26 04:02

user3023925


2 Answers

Change Controller namespace from

namespace App\Http\Controllers

to

namespace App\Http\Controllers\Input
like image 133
pinkal vansia Avatar answered Feb 14 '26 17:02

pinkal vansia


  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');
         }
     }
    
like image 21
cmac Avatar answered Feb 14 '26 17:02

cmac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!