phplaravel-5routesresourcescontrollers

Getting Controller does not exist after moving my controller to sub folder in laravel 5


I have created a resource full route which was pointing to a CRUD controller in App/Http/Controller/SeatController.php my Route in api.php

Route::resource('websites', 'SeatController');

I wanted to put all controllers related to Seat inside a directory. I created a directory named Seat and I moved all of my controllers related to Seat to it. it's path is : App\Http\Controllers\Seat\SeatController

before change it's path was : App\Http\Controllers\SeatController

After above changes I added Seat directory name to my resource full route like :

Route::resource('websites', 'Seat\SeatController');

But when I'm reaching this controller I get below error message :

Class App\Http\Controllers\Seat\SeatController does not exist

UPDATE : my SeatController.php file is like :

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Seat;
use Auth;
use Validator;

class SeatController extends Controller
{

When I change it to :

namespace App\Http\Controllers\Seat;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Seat;
use Auth;
use Validator;

class SeatController extends Controller
{

I Get this error message :

SeatController.php line 12:
Class 'App\Http\Controllers\Seat\Controller' not found

any one knows how to fix this ?


Solution

  • Class App\Http\Controllers\Seat\SeatController does not exist

    This means controller can not find out the SeatController class. You should check following steps. Hope this will be worked for you.

    First you have to check model call in your SeatController file is ok or not. And then check your namespace in SeatController is ok or not. Try with Something like below:

    namespace App\Http\Controllers\Seat;
    
    use App\Seat; \\type your Model name instead of Seat