A route connects a URL and HTTP method to the code that should run. Web routes live in routes/web.php.
Basic routes
Route::get('/about', ...)— show a pageRoute::post('/contact', ...)— receive a formRoute::put,Route::patch,Route::delete— update and deleteRoute::view('/terms', 'terms')— return a view directly
Route parameters
Put a parameter in curly braces: /users/{id}. Laravel passes it to your function. Add ? for an optional parameter: /hello/{name?} — and give it a default value.
Named routes
Give a route a name with ->name('posts.index'), then build its URL anywhere with route('posts.index'). If the URL changes later, every link still works.
See all routes
Run php artisan route:list to see every route, its method, name and controller.
Example
<?php
use Illuminate\Support\Facades\Route;
Route::get('/users/{id}', function (int $id) {
return "User number $id";
})->name('users.show');
Route::get('/hello/{name?}', function (string $name = 'Guest') {
return "Hello, $name";
});
// Building a URL from the name:
// route('users.show', 5) => http://127.0.0.1:8000/users/5
/users/5 shows "User number 5". /hello shows "Hello, Guest" and /hello/Asha shows "Hello, Asha".