1

I have started working on Laravel recently and I have installed Laravel Framework 8.5.0.

Following is my controller "UserController.php"

namespace App\Http\Controllers; use Illuminate\Http\Request; class UserController extends Controller { // public function index(){ return "hello world"; } } 

and here's my web.php in routes

 Route::get('/users', 'UserController@index'); 

When ever I try accessing http://127.0.0.1:8000/users, It just hits me with following error

Illuminate\Contracts\Container\BindingResolutionException

Target class [UserController] does not exist.

3
  • 1
    Check if this question helps you stackoverflow.com/q/63807930/14066311 Commented Sep 20, 2020 at 14:00
  • 1
    Change Route::get('/users', 'UserController@index'); to Route::get('/users', 'App\Http\Controllers\UserController@index'); Commented Sep 20, 2020 at 14:01
  • very good ....... Commented Oct 14, 2023 at 5:25

1 Answer 1

11

according to laravel doc

you can do it in two ways:

1- Using PHP callable syntax...

use App\Http\Controllers\UserController; Route::get('/users', [UserController::class, 'index']); 

2- Using string syntax...

Route::get('/users', 'App\Http\Controllers\UserController@index'); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.