PHPackages                             dentro/yalr - 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. dentro/yalr

ActiveLibrary

dentro/yalr
===========

Class base routing for laravel application.

v1.6.0(2mo ago)815.7k↑191.7%5[4 issues](https://github.com/digital-entropy/yalr/issues)[1 PRs](https://github.com/digital-entropy/yalr/pulls)1MITPHPPHP &gt;=8.3CI passing

Since Oct 18Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/digital-entropy/yalr)[ Packagist](https://packagist.org/packages/dentro/yalr)[ RSS](/packages/dentro-yalr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (14)Used By (1)

YALR (Yet Another Laravel Router)
=================================

[](#yalr-yet-another-laravel-router)

[![Test](https://github.com/digital-entropy/yalr/workflows/Test/badge.svg)](https://github.com/digital-entropy/yalr/workflows/Test/badge.svg)[![Coding Standard](https://github.com/digital-entropy/yalr/workflows/Coding%20Standard/badge.svg)](https://github.com/digital-entropy/yalr/workflows/Coding%20Standard/badge.svg)[![codecov](https://camo.githubusercontent.com/c47a6d4a60f2f20320eccb8ee1bd855156ec6e1b401f79b3ac78213f00499a2e/68747470733a2f2f636f6465636f762e696f2f67682f6469676974616c2d656e74726f70792f79616c722f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d4e6557757776774f416b)](https://codecov.io/gh/digital-entropy/yalr)[![Total Downloads](https://camo.githubusercontent.com/dc2bbb23c2aa4e6bb959f5a89e1ff73ec3fc4ee94e50c60e08c0f88c8d5565bd/68747470733a2f2f706f7365722e707567782e6f72672f64656e74726f2f79616c722f646f776e6c6f616473)](https://packagist.org/packages/dentro/yalr)[![Laravel Octane Compatible](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://github.com/laravel/octane)

Define Laravel routes in different ways using [Class Wrapper Route](#class-wrapper-route) or [Route Attribute](#route-attribute)

Previously known as [jalameta/router](https://github.com/jalameta/jps-router).

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Requirements](#requirements)
- [Getting Started](#getting-started)
- [Class Wrapper Route](#class-wrapper-route)
    - [Creating New Route](#creating-new-route)
    - [Routes Configuration](#routes-configuration)
    - [Class Structure](#class-structure)
    - [Using Controller](#using-controller)
    - [Route Prefix](#route-prefix)
    - [Route Name](#route-name)
- [Preloads](#preloads)
- [Route Attribute](#route-attribute)
    - [Available Class Target](#available-class-target)
    - [Available Method Target](#available-method-target)
    - [Detailed Attribute Examples](#detailed-attribute-examples)
- [Auto Controller Injection](#auto-injection)
- [Available Commands](#available-commands)
    - [yalr:install](#yalrinstall)
    - [yalr:display](#yalrdisplay)
    - [yalr:generate](#yalrgenerate)
    - [make:route](#makeroute)

Installation
------------

[](#installation)

Using Composer:

```
composer require dentro/yalr
```

Requirements
------------

[](#requirements)

LaravelYalrPHP8.x^1.0^8.09.x^1.1^8.010.x^1.2^8.011.x^1.3^8.112.x^1.4^8.212.x^1.5^8.3Getting Started
---------------

[](#getting-started)

After installation, run the following command in your project:

```
php artisan yalr:install
```

Class Wrapper Route
-------------------

[](#class-wrapper-route)

Class wrapper route is our effort to make routing in Laravel more expressive and organized. Routes are represented by their namespace for easier understanding. For example, class `App\Admin\TransactionRoute` will correspond to the route `/app/admin/transaction`.

### Creating New Route

[](#creating-new-route)

To create a new route, run:

```
php artisan make:route DefaultRoute
```

This command will create a route named `DefaultRoute` in `app/Http/Routes/DefaultRoute.php`. Note that after creation, you must register the Route class in your route configuration for it to be loaded.

#### make:route Options

[](#makeroute-options)

##### 1. Inject

[](#1-inject)

The `--inject` option automatically adds the route class name to your route configuration:

```
php artisan make:route DefaultRoute --inject web
```

This command creates the Default route and adds it to the web group defined in `config/routes.php`.

##### 2. Controller

[](#2-controller)

The `--controller` option generates both the route and its associated controller with the same name:

```
php artisan make:route DefaultRoute --controller
```

This eliminates the need to run two separate commands to create a controller and route.

##### 3. Help

[](#3-help)

Shows the YALR command help information.

### Routes Configuration

[](#routes-configuration)

Here's an example of a YALR configuration file:

```
return [
    'groups' => [
        'web' => [
            'middleware' => 'web',
            'prefix' => '',
        ],
        'api' => [
            'middleware' => 'api',
            'prefix' => 'api',
        ],
    ],

    'web' => [
        \App\Http\Routes\DefaultRoute::class,
    ],
    'api' => [
        //
    ],

    // Auto-injection configuration for yalr:generate command
    'injects' => [
        'web' => ['app/Http/Controllers/Web/'],
        'api' => ['app/Http/Controllers/Api/']
    ],
];
```

The `groups` section defines group configurations where you can specify Laravel options such as `as`, `domain`, `middleware`, `prefix`, etc. The `web` and `api` sections contain arrays of route class names that belong to these groups.

### Class Structure

[](#class-structure)

Here's an example of a generated route file:

```
