Repolode
spatie

spatie/laravel-route-attributes

A Laravel package that lets you register routes by placing PHP 8 attributes directly on controller classes and methods.

Stars
883
Forks
85
Open issues
0
Last commit
2 days ago

What is it?

laravel-route-attributes lets Laravel developers declare routes next to the controller code they point to. Adding an attribute such as #[Get('my-route')] to a controller method causes the package to register the equivalent Route::get call, so routes no longer need to be maintained in a separate routes file.

The package scans configured controller directories and supports every common HTTP verb, plus a Resource attribute for resource controllers and an ApiResource variant. Attributes also cover route names, middleware, prefixes, domains, group definitions, parameter constraints such as WhereUuid or WhereNumber, default parameter values, scoped bindings, and soft-deleted model binding.

Directories can be configured with per-directory middleware, prefixes and namespaces, which suits modular applications. File patterns and exclusion patterns let you limit scanning to specific files, such as only controller files in a folder that also contains tests.

Key features

  • 01Register routes with PHP 8 attributes on controller classes and methods.
  • 02Supports all standard HTTP verbs plus multi-verb and any-verb routes.
  • 03Resource and ApiResource attributes generate resource routes with only/except and naming options.
  • 04Attributes for middleware, prefixes, domains, route names, and parameter constraints.
  • 05Directory configuration with per-directory middleware, prefixes, and namespaces.
  • 06File pattern and exclusion options to control which files are scanned.

Use cases

  • Keeping routes co-located with controllers in a Laravel application.
  • Organizing routes for modular Laravel projects that keep controllers in separate module directories.
  • Building REST APIs with resource routes declared directly on controllers.

Quick start

  1. 1

    Install the package with Composer

    composer require spatie/laravel-route-attributes
  2. 2

    Publish the config file

    php artisan vendor:publish --provider="Spatie\RouteAttributes\RouteAttributesServiceProvider" --tag="config"
  3. 3

    Add route attributes to your controller classes and methods

In collections

Topics

FAQ

What is laravel-route-attributes?
A Laravel package that lets you register routes by placing PHP 8 attributes directly on controller classes and methods. laravel-route-attributes lets Laravel developers declare routes next to the controller code they point to. Adding an attribute such as #[Get('my-route')] to a controller method causes the package to register the equivalent Route::get call, so routes no longer need to be maintained in a separate routes file.
Is laravel-route-attributes free to use? What license does it have?
laravel-route-attributes is open source under the MIT license. Check the license terms before using it in commercial products.
Is laravel-route-attributes still maintained?
Actively maintained. The last commit to laravel-route-attributes was on Nov 5, 2026.
What can I use laravel-route-attributes for?
Keeping routes co-located with controllers in a Laravel application. Organizing routes for modular Laravel projects that keep controllers in separate module directories. Building REST APIs with resource routes declared directly on controllers.
How do I install laravel-route-attributes?
Install the package with Composer: composer require spatie/laravel-route-attributes Publish the config file: php artisan vendor:publish --provider="Spatie\RouteAttributes\RouteAttributesServiceProvider" --tag="config" Add route attributes to your controller classes and methods
Where can I get laravel-route-attributes?
The source code and installation instructions are on GitHub: https://github.com/spatie/laravel-route-attributes

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects