1

This is my controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;


class PagesController extends Controller
{
    public function index(){
        return 'INDEX';
    }
}

and this is my route

use Illuminate\Support\Facades\Route;

Route::get('/', 'PagesController@index');

Route::get('/about', function () {
    return view('pages.about');
});

the result is

Illuminate\Contracts\Container\BindingResolutionException

Target class [PagesController] does not exist.

How can I solve this issue?

  • `'PagesController@index'` doesn't contain namespace information. Does it work if you add `use App\Http\Controllers\UserController;` and replace it with `[PagesController::class, 'index']`? – Álvaro González Oct 07 '20 at 15:28
  • Thank you very much man. Tried a bunch of other stuff found on internet but this is the first one that worked. – Ibraheem Ahmed Oct 07 '20 at 15:39

1 Answers1

0

Make sure your PagesController.php file is in App\Http\Controllers

and Run

composer dump-autoload

for laravel8 route need to change with

Route::get('/', [PagesController::class, 'index']);

Kotzilla
  • 1,333
  • 18
  • 27