Basic Routing in PHP
From the Laravel cheat sheet · Routing · verified Jul 2026
Basic Routing
Defining routes and HTTP verbs
php
// routes/web.php
// Basic routes
Route::get('/', function () {
return view('welcome');
});
Route::get('/users', [UserController::class, 'index']);
Route::post('/users', [UserController::class, 'store']);
Route::put('/users/{id}', [UserController::class, 'update']);
Route::delete('/users/{id}', [UserController::class, 'destroy']);
// Route parameters
Route::get('/users/{id}', function ($id) {
return User::find($id);
});
// Optional parameters
Route::get('/posts/{id?}', function ($id = null) {
return $id ?? 'All posts';
});💡 Use route model binding for automatic model resolution
⚡ Group routes to apply common middleware, prefixes, or namespaces
📌 Named routes prevent hardcoding URLs in views
🔥 Use where() constraints to validate route parameters