Open-Source Wikis

/

Laravel

/

Systems

/

Routes

laravel/laravel

Routes

Active contributors: Taylor Otwell

Purpose

Route registration. The skeleton ships two route files — one for HTTP, one for Artisan commands. Both are loaded by bootstrap/app.php's withRouting() call.

Directory layout

routes/
├── console.php   # Artisan command definitions
└── web.php       # HTTP routes (web middleware group)

There is no routes/api.php or routes/channels.php by default. Add them yourself and reference them from bootstrap/app.php if needed.

routes/web.php

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return view('welcome');
});

That's it — three lines and a single closure-based route. GET / renders resources/views/welcome.blade.php.

Two implicit behaviours:

  • Web middleware. Routes registered here are wrapped in the framework's "web" middleware group automatically: cookies, sessions, CSRF, view sharing, etc. The exact list lives inside Illuminate\Foundation\Configuration\Middleware.
  • CSRF. Because the web group is applied, any POST route here would expect a _token field or X-CSRF-TOKEN header.

bootstrap/app.php also registers GET /up via withRouting(health: '/up'). This one isn't visible in web.php — it's wired by the framework.

routes/console.php

<?php

use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;

Artisan::command('inspire', function () {
    $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote');

The single command (php artisan inspire) prints a randomly chosen inspirational quote from Illuminate\Foundation\Inspiring::quote(). The ->purpose(...) chained call sets the description shown in php artisan list.

This is the modern Laravel pattern: trivial commands declared as closures right in routes/console.php. Larger commands still go in dedicated classes under app/Console/Commands/ and are auto-registered via Artisan's discovery — but the skeleton has no such classes.

Adding routes

You want to… Edit… Example
Add a controller-backed route routes/web.php Route::get('/profile', [ProfileController::class, 'show']);
Add an Artisan command routes/console.php Artisan::command('queue:rotate', fn() => /* ... */)->purpose('Rotate queue keys');
Add API routes Create routes/api.php Then add api: __DIR__.'/../routes/api.php' to withRouting() in bootstrap/app.php
Schedule a recurring task routes/console.php Schedule::command('inspire')->hourly();Schedule facade is auto-imported by Artisan
Group routes under a prefix Inside routes/web.php Route::prefix('admin')->group(function () { /* ... */ });

How routes hook into the framework

graph LR
    BootstrapApp[bootstrap/app.php] -->|withRouting web| WebRoutes[routes/web.php]
    BootstrapApp -->|withRouting commands| ConsoleRoutes[routes/console.php]
    BootstrapApp -->|withRouting health| HealthRoute[GET /up]
    WebRoutes --> Router[Illuminate\Routing\Router]
    ConsoleRoutes --> Schedule[Illuminate\Console\Scheduling\Schedule]
    HealthRoute --> Router
    Router --> Dispatch[Dispatch incoming HTTP request]
    Schedule --> ArtisanList[php artisan list/run]

Integration points

  • bootstrap/app.php — the withRouting() call is the only thing that loads these files.
  • resources/views/welcome.blade.php — referenced by the single web route.
  • Illuminate\Foundation\Inspiring (framework code) — provides the quotes for the inspire command.

Entry points for modification

Almost every change to routing happens here. Adding routes, adding command closures, defining route groups — all in routes/web.php or routes/console.php. Middleware groups and aliases are configured in bootstrap/app.php rather than per-route, but middleware can still be applied per-route with the standard ->middleware(['auth', 'verified']) chain.

Key source files

File Purpose
routes/web.php Web route registration — one route to render the welcome page
routes/console.php Artisan command definitions — one closure for inspire

See Bootstrap for the withRouting() call that wires both files in, and Resources for the welcome view rendered by the only web route.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Routes – Laravel wiki | Factory