0

Why ::class is written in Laravel 8 web.php

Route::get('/', [UserController::class, 'show']);
shaedrich
  • 5,457
  • 3
  • 26
  • 42

1 Answers1

3

Class is just a constant provided by PHP. You can do either

Route::get('/', [UserController::class, 'show']);

or

Route::get('/', 'App\Http\Controllers\UserController@show');

When you use the class you can import it on top of your file by using use and you don't have to store it in strings like the second example.

Kevin
  • 1,152
  • 5
  • 13