Performance: Resource routes
Resource routes affect the routing system's efficiency and the initial request handling speed in Laravel applications.
Route::resource('posts', PostController::class);
Route::get('/posts', [PostController::class, 'index']); Route::get('/posts/create', [PostController::class, 'create']); Route::post('/posts', [PostController::class, 'store']); Route::get('/posts/{post}', [PostController::class, 'show']); Route::get('/posts/{post}/edit', [PostController::class, 'edit']); Route::put('/posts/{post}', [PostController::class, 'update']); Route::delete('/posts/{post}', [PostController::class, 'destroy']);
| Pattern | Routing Table Size | Route Matching Time | Maintenance Cost | Verdict |
|---|---|---|---|---|
| Manual route definitions for each CRUD action | Large (7 entries per resource) | Higher due to more entries | High, repetitive code | [X] Bad |
| Single resource route definition | Small (1 entry per resource) | Lower due to fewer entries | Low, concise code | [OK] Good |
Route::resource('photos', PhotoController::class) method do in Laravel?PostController?Route::resource('books', BookController::class)->only(['index', 'show']);, which URLs will be available?Route::resource('users', UserController::class)->except('store');ArticleController but only allow routes for creating, storing, and editing articles. Which is the correct route definition?Pass the test and this pattern moves unknown