Introduction
Routing connects website addresses (URLs) to the code that runs when you visit them. It helps the app know what to do for each URL.
Routing connects website addresses (URLs) to the code that runs when you visit them. It helps the app know what to do for each URL.
Route::get('/url', function () {
// logic to run
});Route::get('/', function () { return 'Welcome page'; });
Route::get('/user/{id}', function ($id) { return "User ID: $id"; });
Route::post('/submit', function () {
// handle form submission
});This example shows three routes: home, about, and a user profile with an ID. Each URL runs different code to show a message.
<?php use Illuminate\Support\Facades\Route; Route::get('/', function () { return 'Home page'; }); Route::get('/about', function () { return 'About us page'; }); Route::get('/user/{id}', function ($id) { return "User profile for user $id"; });
Routes should be defined in the routes/web.php file in Laravel.
Use curly braces {} to capture parts of the URL as variables.
Routing helps keep your app organized and easy to understand.
Routing links URLs to the code that runs for them.
It lets you create different pages and actions for different URLs.
Laravel uses simple syntax to define routes with Route::get or Route::post.
Route::get('/greet', function () { return 'Hello, Laravel!'; });Route::get('/user', function { return 'User page'; });Pass the test and this pattern moves unknown