All Routing lessons

Basic routes

4 min read

Routes live in routes/web.php (browser-facing) and routes/api.php (token-authenticated JSON). Each one binds an HTTP verb + URI to a closure or controller method.

use App\Http\Controllers\PostController;

Route::get('/posts',         [PostController::class, 'index']);
Route::post('/posts',        [PostController::class, 'store']);
Route::put('/posts/{post}',  [PostController::class, 'update']);
Route::delete('/posts/{post}', [PostController::class, 'destroy']);

The 7 verbs Laravel supports

GET · HEAD · POST · PUT · PATCH · DELETE · OPTIONS

For RESTful resources you rarely declare these by hand — Route::resource('posts', PostController::class) registers all seven in one line.

Closures vs controllers

Closures are fine for quick prototypes:

Route::get('/ping', fn () => response()->json(['ok' => true]));

For anything real, point at a controller — it keeps logic out of route files and lets php artisan route:cache work.