Resource controllers map the seven standard CRUD actions to a controller with a single route declaration.
php artisan make:controller PostController --resource --model=Post
| Verb | URI | Action | Route Name |
|-----------|----------------------|---------|----------------|
| GET | /posts | index | posts.index |
| GET | /posts/create | create | posts.create |
| POST | /posts | store | posts.store |
| GET | /posts/{post} | show | posts.show |
| GET | /posts/{post}/edit | edit | posts.edit |
| PUT/PATCH | /posts/{post} | update | posts.update |
| DELETE | /posts/{post} | destroy | posts.destroy |
// All seven actions at once
Route::resource('posts', PostController::class);
// Limit to specific actions
Route::resource('photos', PhotoController::class)->only(['index', 'show']);
Route::resource('comments', CommentController::class)->except(['destroy']);
// routes/api.php
Route::apiResource('posts', PostController::class);
Route::resource('posts.comments', PostCommentController::class);
// Generates routes like: /posts/{post}/comments/{comment}