Why ::class
is written in Laravel 8 web.php
Route::get('/', [UserController::class, 'show']);
Why ::class
is written in Laravel 8 web.php
Route::get('/', [UserController::class, 'show']);
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.