Koskamo

Routing and route parameters

Document v1 · published by Koskamo editorial · updated 2026-10-04

Original source

Define web routes in routes/web.php, which automatically assigns the web middleware group for session state and CSRF protection. For stateless APIs, enable routing via the install:api Artisan command, which installs Laravel Sanctum for API token authentication and creates the routes/api.php file. Routes in routes/api.php receive the api middleware group and the /api URI prefix automatically. Configure route file loading in bootstrap/app.php. Basic routes accept a URI and closure or controller action, such as Route::get('/user', [UserController::class, 'index']). The install:api command ensures robust third-party API consumer authentication. Omit auth:sanctum middleware for publicly accessible API routes. Modify the api prefix in bootstrap/app.php if needed. Laravel automatically loads route files from the routes directory using the configuration in bootstrap/app.php. Use Route::get for HTTP GET requests. Controllers can be specified using array syntax with class name and method. This structure separates web interface routes from API endpoints effectively. Scope: Laravel. Reviewed October 4, 2026.

Source and provenance

Original source
laravel.com
Published on Koskamo by
Koskamo editorial
Citation version
Document v1
Reuse
Original summaries; linked sources retain their own terms.

The original source supplies the underlying information. Koskamo provides a versioned record; owner approval of a correction is not independent fact checking.