Imran Saleem
Imran Saleem

Reputation: 380

Need to change Laravel controller path already set namespace empty on serviceprovider

I want to change the path of route, but it's still giving error

Class HomeController does not exist

below is my code

In app/Http/routes.php page

Route::get('admin/restaurantMenu', 'HomeController@index');

In app/Provider/RouteServiceProvider.php page

protected $namespace = '';

Home controller page on root HomeController.php See the attached image

and i have already try

  1. composer dump-autoload
  2. php artisan optimize
  3. php artisan route:clear
  4. php artisan route:cache

HomeController.php

Upvotes: 1

Views: 1505

Answers (1)

Scootaloot
Scootaloot

Reputation: 41

By default your router will be in the 'App/Http/Controllers' namespace. (I cant see that you have kept that namespace as you have cut off the image, but I am assuming... I know... I shouldnt assume)

So by changing

protected $namespace = 'App\Http\Controllers';

to be

protected $namespace = ''

Laravel is trying to match 'App\Http\Controllers\HomeController' with 'HomeController' and not finding it.

You should change the protected $namespace back to what it was and it should start to work.

Is there a reason why you have moved the controller into the root of your application? Whilst Laravel makes it pretty easy to move things around, keeping all your controllers together should make for a much easier to understand application.

The route itself controls the URL rather than the location of the controller file within app/.

Hope fully this was helpful?

Upvotes: 2

Related Questions