0

I created a Panel directory inside Controller directory .

enter image description here

there is a login function inside AdminController.php

class AdminController extends Controller
{
    //


    public function login()
    {
        return 'test';
    }
}

in routes.php I wrote a route like this:

Route::get('/cp/login','Panel\AdminController@login');

but when I run below url I got some errors that there isn't exist this controller :

http://localhost:8000/cp/login

ReflectionException in Route.php line 280: Class App\Http\Controllers\Panel\AdminController does not exist

8
  • It could be that laravel hasn't updated autoloder. Did you run composer dump-autoload? Commented Jul 7, 2016 at 10:50
  • 1
    try to set your controller namespace to App\Http\Controllers\Panel Commented Jul 7, 2016 at 10:51
  • try to run composer dump-autoload Commented Jul 7, 2016 at 10:52
  • 1
    stackoverflow.com/questions/18850542/… check this you will get your solution Commented Jul 7, 2016 at 10:53
  • @Pardeep Pathania I used dump-autoload but doesn't work Commented Jul 7, 2016 at 10:55

2 Answers 2

1

Try adding the appropriate namespace to the top of the AdminController file, you will also need to specify the namespace for the Controller class that it extends, as they are under different sub-namespaces.

You can read more about PSR-4 autoloading here http://www.php-fig.org/psr/psr-4/.

Based on the directory structure that you have there it should read

<?php

    namespace App\Http\Controllers\Panel

    use App\Http\Controllers\Controller;

    class AdminController extends Controller {

        //..

    }
Sign up to request clarification or add additional context in comments.

1 Comment

your answer true but u must add this line : use App\Http\Controllers\Controller;
1

you should add the namespace to the contorller

Change you namespace to

namespace App\Http\Controllers\Panel;

Laravel will resolve controllers based on your name spacing, not on your directory structure.

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.