🎓 A1Learner
🔍
0 of 50 lessons completed

Laravel Your First Route

A route links a web address to code. A route sends a visitor to the right code when the visitor opens its address.

A hello route

This route answers /l06/hello with a greeting.

Route::get('/l06/hello', fn () => 'Hello, Laravel!');

Another page

This route answers /l06/about with a short line.

Route::get('/l06/about', fn () => 'About this app');

A goodbye route

This route answers /l06/goodbye with a farewell.

Route::get('/l06/goodbye', fn () => 'Goodbye, Laravel!');

Example

<?php

use Illuminate\Support\Facades\Route;

Route::get('/l06/hello', fn () => 'Hello, Laravel!');

Key points

  • Route: a link between a web address and code.
  • Routes for web pages live in routes/web.php.
  • Route::get handles a visit to an address.
  • Route closure: a small function written inside the route, with no name.
  • A closure returns the text the visitor sees.

In this example, the first lines load the Route helper. The last line adds a route for /l06/hello. A visit to that address sees Hello, Laravel!

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Where do routes for web pages live?