HTTP Verbs

Register routes for GET, POST, PUT, PATCH and DELETE.

SyntaxRoute::post('/uri', $callback);

The Route facade has a method for each HTTP verb, matching the intent of the request:

  • Route::get() — read data.
  • Route::post() — create data.
  • Route::put() / patch() — update data.
  • Route::delete() — remove data.

Example

Example · php
use Illuminate\Support\Facades\Route;

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

When to use it

  • A REST API defines separate GET, POST, PUT, and DELETE routes for the /articles resource so each HTTP verb maps to a distinct controller action.
  • A checkout page uses Route::match(['get','post'], '/checkout', ...) so the same URL handles both displaying the form and processing the submission.
  • A public status endpoint registers Route::any('/health', ...) so monitoring tools can probe it with any HTTP method without a 405 response.

More examples

All HTTP verb methods

Shows all six HTTP verb methods available in Laravel routing, each mapping to a separate controller action.

Example · php
Route::get('/articles',          [ArticleController::class, 'index']);
Route::post('/articles',         [ArticleController::class, 'store']);
Route::put('/articles/{id}',     [ArticleController::class, 'update']);
Route::patch('/articles/{id}',   [ArticleController::class, 'patch']);
Route::delete('/articles/{id}',  [ArticleController::class, 'destroy']);
Route::options('/articles',      [ArticleController::class, 'options']);

Match multiple verbs on one route

Route::match() limits the route to a specified list of HTTP verbs, while Route::any() accepts all verbs — useful for health-check endpoints.

Example · php
// Accept GET (display form) and POST (process form) on the same URL
Route::match(['get', 'post'], '/checkout', [CheckoutController::class, 'handle']);

// Accept any verb
Route::any('/health', fn() => response()->json(['status' => 'ok']));

Full resource controller in one line

Route::resource() generates the full suite of CRUD routes; only() and except() restrict which verbs are registered.

Example · php
// Generates 7 routes covering all CRUD verbs
Route::resource('posts', PostController::class);

// Limit to specific verbs
Route::resource('photos', PhotoController::class)
    ->only(['index', 'show']);

// Exclude specific verbs
Route::resource('comments', CommentController::class)
    ->except(['destroy']);

Discussion

  • Be the first to comment on this lesson.