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.

lagbox
  • 48,571
  • 8
  • 72
  • 83
Waqas Yousaf
  • 64
  • 1
  • 3
  • 10
  • 1
    Check if this question helps you https://stackoverflow.com/q/63807930/14066311 – Prince Dorcis Sep 20 '20 at 14:00
  • Change `Route::get('/users', 'UserController@index');` to `Route::get('/users', 'App\Http\Controllers\UserController@index');` – STA Sep 20 '20 at 14:01

1 Answers1

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');
OMR
  • 11,736
  • 5
  • 20
  • 35