laravel 8
You can define a route to this controller method like so:
use App\Http\Controllers\UserController;
Route::get('/users', [UserController::class, 'index']);
Route::get('/user/{id}', [UserController::class, 'show']);
Resource Controllers
resourceful route to the controller:
use App\Http\Controllers\PhotoController;
Route::resource('photos', PhotoController::class);
------------------------------------------------------------------------------------
laravel 7, 6, 5
You can define a route to this controller method like so:
Route::get('users', 'UserController@index');
Route::get('user/{id}', 'UserController@show');
Resource Controllers
resourceful route to the controller:
Route::resource('photos', 'PhotoController');
=========================================
This single route declaration creates multiple routes to handle a variety of actions on the resource. The generated controller will already have methods stubbed for each of these actions. Remember, you can always get a quick overview of your application's by running the
route:list
Artisan command.
Actions Handled By Resource Controller
Verb URI Action Route Name
GET /photos index photos.index
GET /photos/create create photos.create
POST /photos store photos.store
GET /photos/{photo} show photos.show
GET /photos/{photo}/edit edit photos.edit
PUT/PATCH /photos/{photo} update photos.update
DELETE /photos/{photo} destroy photos.destroy