PHPackages                             izniburak/laravel-auto-routes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. izniburak/laravel-auto-routes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

izniburak/laravel-auto-routes
=============================

Auto Route Generating (Auto-Discovery) Package for Laravel

v2.1.0(1y ago)23645.3k↓21.2%16MITPHPPHP ^8.1

Since May 6Pushed 1y ago5 watchersCompare

[ Source](https://github.com/izniburak/laravel-auto-routes)[ Packagist](https://packagist.org/packages/izniburak/laravel-auto-routes)[ Docs](https://github.com/izniburak/laravel-auto-routes)[ Fund](https://buymeacoff.ee/izniburak)[ GitHub Sponsors](https://github.com/izniburak)[ RSS](/packages/izniburak-laravel-auto-routes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (15)Used By (0)

Laravel Auto Routes
-------------------

[](#laravel-auto-routes)

```
                _              _____             _
     /\        | |            |  __ \           | |
    /  \  _   _| |_ ___ ______| |__) |___  _   _| |_ ___  ___
   / /\ \| | | | __/ _ \______|  _  // _ \| | | | __/ _ \/ __|
  / ____ \ |_| | || (_) |     | | \ \ (_) | |_| | ||  __/\__ \
 /_/    \_\__,_|\__\___/      |_|  \_\___/ \__,_|\__\___||___/

```

[![Total Downloads](https://camo.githubusercontent.com/7179aef4ff7c322c0e23b70feeb33ab1f464e0d43a49408d17da3d118a919cdd/68747470733a2f2f706f7365722e707567782e6f72672f697a6e69627572616b2f6c61726176656c2d6175746f2d726f757465732f642f746f74616c2e737667)](https://packagist.org/packages/izniburak/laravel-auto-routes)[![Latest Stable Version](https://camo.githubusercontent.com/8d52bc3d55f401c24527ba89e640fd4780cc56f2cdbd6aff3c647de0f1f8a218/68747470733a2f2f706f7365722e707567782e6f72672f697a6e69627572616b2f6c61726176656c2d6175746f2d726f757465732f762f737461626c652e737667)](https://packagist.org/packages/izniburak/laravel-auto-routes)[![Latest Unstable Version](https://camo.githubusercontent.com/eaf8eeef23721b3a72250b63099483b4f66dce7599aee94b7c6da2f5a1c459a7/68747470733a2f2f706f7365722e707567782e6f72672f697a6e69627572616b2f6c61726176656c2d6175746f2d726f757465732f762f756e737461626c652e737667)](https://packagist.org/packages/izniburak/laravel-auto-routes)[![License](https://camo.githubusercontent.com/ff679c1ec7221b29519adb8bf980511613284501ff89217528175c7f8f55f853/68747470733a2f2f706f7365722e707567782e6f72672f697a6e69627572616b2f6c61726176656c2d6175746f2d726f757465732f6c6963656e73652e737667)](https://packagist.org/packages/izniburak/laravel-auto-routes)

Automatically Route Generator &amp; Discovery Package for Laravel.

Features
--------

[](#features)

- All HTTP Methods which supported by Laravel
- AJAX supported HTTP Methods (XMLHttpRequest)
- Custom patterns for parameters with Regex
- kebab-case and snake\_case supported URLs
- Livewire routes support \[included Volt\] *(in v2.x)*

Install
-------

[](#install)

Supported Laravel Versions:

- v2.x: Laravel 10 and later
- v1.x: Laravel 6 and later ([see the source](https://github.com/izniburak/laravel-auto-routes/tree/1.x))

Run the following command directly in your Project path:

```
composer require izniburak/laravel-auto-routes
```

**OR** open your `composer.json` file and add the package like this:

```
{
    "require": {
        "izniburak/laravel-auto-routes": "^2.0"
    }
}
```

after run the install command.

```
composer install
```

The service provider of the Package will be **automatically discovered** by Laravel.

After that, you should publish the config file via following command:

```
php artisan vendor:publish --provider="Buki\AutoRoute\AutoRouteServiceProvider"
```

Greate! You can start to use **Auto Route** Package.

Usage
-----

[](#usage)

Open `web.php` or `api.php` files in `routes` directory, and add a new route that will be generated automatically:

```
Route::auto('/test', 'TestController');
```

All methods will be automatically generated by the AutoRoute Package.

Details
-------

[](#details)

- You can use `auto-route.php` file in `config` directory in order to change configuration of the Package. You can;

    - add new patterns for the parameters of the methods.
    - change default HTTP methods.
    - change main method.
- You can use `Buki\AutoRoute\Facades\Route` in `web.php` and `api.php` in order to simple code completion for the method while using an IDE or Editor. You can add/replace the following line to top of the file:

```
// use Illuminate\Support\Facades\Route;
use Buki\AutoRoute\Facades\Route;
```

- All methods which will be auto generated must have `public` accessor to discovered by the **AutoRoute** Package.

### Methods

[](#methods)

- If you use `camelCase` style for your method names in the Controllers, these methods endpoints will automatically convert to `kebab-case` to make pretty URLs. For example:

```
Route::auto('/test', 'TestController');
# OR
Route::auto('/test', TestController::class);
```

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL will be converted to "/test/foo-bar"
     */
    public function fooBar(Request $request)
    {
        // your codes
    }
}
```

- You can specify HTTP Method for the method of the Controllers. If you want that a method works with `GET` method and other method works with `POST` method, you can do it. Just add a prefix for the method. That's all. For example;

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test/foo-bar"
     * This method will only work with 'GET' method.
     */
    public function getFooBar(Request $request)
    {
        // your codes
    }

    /**
     * URL: "/test/bar-baz"
     * This method will only work with 'POST' method.
     */
    public function postBarBaz(Request $request)
    {
        // your codes
    }
}
```

- If you don't add any prefix to your methods to use HTTP method definition, all URL will work with all HTTP methods. This options can be changed from `auto-route.php` configuration file.
- If you want to use `snake_case` format for your methods, you can do it like that:

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test/foo_bar"
     * This method will only work with 'GET' method.
     */
    public function get_foo_bar(Request $request)
    {
        // your codes
    }

    /**
     * URL: "/test/bar_baz"
     * This method will only work with 'POST' method.
     */
    public function post_bar_baz(Request $request)
    {
        // your codes
    }
}
```

### Ajax Supported Methods

[](#ajax-supported-methods)

Also, you can add **AJAX supported** routes. For example; If you want to have a route which only access with GET method and XMLHttpRequest, you can define it simply. This package has some AJAX supported methods. These are;

```
XGET, XPOST, XPUT, XDELETE, XPATCH, XOPTIONS, XANY.

```

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test/foo"
     * This method will only work with 'GET' method and XMLHttpRequest.
     */
    public function xgetFoo(Request $request)
    {
        // your codes
    }

    /**
     * URL: "/test/bar"
     * This method will only work with 'POST' method and XMLHttpRequest.
     */
    public function xpostBar(Request $request)
    {
        // your codes
    }

    /**
     * URL: "/test/baz"
     * This method will work with any method and XMLHttpRequest.
     */
    public function xanyBaz(Request $request)
    {
        // your codes
    }
}
```

As you see, you need to add only `x` char as prefix to define the AJAX supported routes. If you want to support XMLHttpRequest and all HTTP methods which supported by Laravel, you can use `xany` prefix.

For AJAX supported methods, the package will automatically add a middleware in order to check XMLHttpRequest for the routes. This middleware throws a `MethodNotAllowedException` exception. But, you can change this middleware from `auto-routes.php` file in `config` directory, if you want.

### Options

[](#options)

- You can add route options via third parameter of the `auto` method.

```
Route::auto('/test', 'TestController', [
    // your options...
]);
```

Options array may contain all Laravel route attributes like `name`, `middleware`, `namespace`, etc..

In addition, you can add `patterns` into the Options array in order to define new patterns for the parameters of the methods in the Controllers. For example:

```
Route::auto('/test', 'TestController', [
    'name' => 'test',
    'middleware' => [YourMiddleware::class],
    'patterns' => [
        'id' => '\d+',
        'value' => '\w+',
    ],
]);
```

According to example above, you can use `$id` and `$value` parameters in all methods in the Controller. And for these parameters, the rules you defined will be applied.

Also, to define default patterns for the parameters, you can modify `patterns` in `auto-route.php` file.

- You can specify the Routes which will be generated automatically by using `only` or `except` with `options` parameters. You should use method names in the Controllers. For example;

```
# First Example
Route::auto('/foo', 'FooController', [
    'only' => ['fooBar', 'postUpdatePost'],
]);

# Second Example
Route::auto('/bar', 'BarController', [
    'except' => ['test', 'putExample'],
]);
```

According to first example above, only two methods will be generated. And according to other example, all methods will be generated except two methods which specified.

- If you don't change the `main_method` in configurations, your main method will be `index` for the Controllers. That's mean, you should be add `index` method into your controller to define base endpoint of the Controller. For example;

```
Route::auto('/test', 'TestController');
```

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test"
     */
    public function index(Request $request)
    {
        // your codes
    }

    /**
     * URL: "/test/foo-bar"
     */
    public function fooBar(Request $request)
    {
        // your codes
    }
}
```

### Parameters

[](#parameters)

- You can use parameters as `required` and `optional` for the methods in your Controllers. For example;

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test/{id}"
     */
    public function index(Request $request, $id)
    {
        // your codes
    }

    /**
     * URL: "/test/foo-bar/{name}/{surname?}"
     */
    public function fooBar(Request $request, $name, $surname = null)
    {
        // your codes
    }
}
```

Also, you can use parameter type to use compatible pattern for the parameter. Parameter types can be `int`, `string`, `float` and `bool`. For example:

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test/{id}"
     * id parameter must be numeric.
     */
    public function index(Request $request, int $id)
    {
        // your codes
    }

    /**
     * URL: "/test/foo-bar/{name}/{surname?}"
     * name and surname parameters must be string.
     */
    public function fooBar(Request $request, string $name, string $surname = null)
    {
        // your codes
    }
}
```

If you define patterns for these variable names in the `auto-route.php` configuration file, your definition will be used for the value checking.

To use `int`, `float`, `string` and `bool` patterns quickly for your parameters, you can use parameter type directly.

- You can use subfolder definition for the Controllers. For example;

```
Route::auto('/test', 'Backend.TestController');
# OR
Route::auto('/test', 'Backend\\TestController');
```

Livewire &amp; Volt support
---------------------------

[](#livewire--volt-support)

You can define Livewire or Volt component routes directly in your controller by using Auto Routes package! For this, you should add new methods which have prefix `volt` or `wire`. That's it. Auto Routes package will automatically discover your Livewire routes and add them into the application routes.

```
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    /**
     * URL: "/test/foo"
     */
    public function voltFoo(): string
    {
        // resources/views/livewire/pages/foo.blade.php
        return 'pages.foo';
    }

    /**
     * URL: "/test/bar"
     */
    public function wireBar(): string
    {
        return \App\Livewire\TestComponent::class;
    }
}
```

As you see; for both methods, you must return a string value that Volt component path string or Livewire component class string. Now, you can access your Livewire components.

Support
-------

[](#support)

You can use Issues

[izniburak's homepage](https://buki.dev)

[izniburak's twitter](https://twitter.com/izniburak)

Licence
-------

[](#licence)

[MIT Licence](http://opensource.org/licenses/MIT)

Contributing
------------

[](#contributing)

1. Fork it (  )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

Contributors
------------

[](#contributors)

- [izniburak](https://github.com/izniburak) İzni Burak Demirtaş - creator, maintainer

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 87.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~91 days

Recently: every ~173 days

Total

14

Last Release

648d ago

Major Versions

1.x-dev → v2.0.02023-11-17

PHP version history (3 changes)v1.0.0PHP ^7.2.5|^8.0

v1.6.0PHP ^7.2.5|^8.0.2

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/9ab12d522ab707c9e0474847ae8299a3a879e12a55dfbc8aebbd579fa6d54140?d=identicon)[izniburak](/maintainers/izniburak)

---

Top Contributors

[![izniburak](https://avatars.githubusercontent.com/u/4693615?v=4)](https://github.com/izniburak "izniburak (27 commits)")[![laradocs](https://avatars.githubusercontent.com/u/49741756?v=4)](https://github.com/laradocs "laradocs (2 commits)")[![aligurbuz](https://avatars.githubusercontent.com/u/8428572?v=4)](https://github.com/aligurbuz "aligurbuz (1 commits)")[![MarceloSantosCorrea](https://avatars.githubusercontent.com/u/5748703?v=4)](https://github.com/MarceloSantosCorrea "MarceloSantosCorrea (1 commits)")

---

Tags

auto-routerlaravelroute-generationrouterlaravelrouterrouteauto-routeroute-generatorroute-discovery

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/izniburak-laravel-auto-routes/health.svg)

```
[![Health](https://phpackages.com/badges/izniburak-laravel-auto-routes/health.svg)](https://phpackages.com/packages/izniburak-laravel-auto-routes)
```

###  Alternatives

[illuminatech/url-trailing-slash

Allows enforcing URL routes with or without trailing slash

50216.9k](/packages/illuminatech-url-trailing-slash)[proai/lumen-annotations

Route and event binding annotations for Laravel Lumen

1012.4k](/packages/proai-lumen-annotations)[amendozaaguiar/filament-route-statistics

Filament route statictics viewer

3225.0k1](/packages/amendozaaguiar-filament-route-statistics)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
