PHPackages                             evolutionphp/routing - 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. [Framework](/categories/framework)
4. /
5. evolutionphp/routing

ActiveLibrary[Framework](/categories/framework)

evolutionphp/routing
====================

PHP Routing

v1.0(1y ago)01[1 issues](https://github.com/EvolutionPHP/routing/issues)MITPHPPHP &gt;=8.2

Since Feb 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/EvolutionPHP/routing)[ Packagist](https://packagist.org/packages/evolutionphp/routing)[ RSS](/packages/evolutionphp-routing/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Routing
=======

[](#routing)

Simple request router for PHP.

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

[](#installation)

Use [Composer](http://getcomposer.org) to install Logger into your project:

```
composer require evolutionphp/routing
```

Usage
-----

[](#usage)

### Basic Routing

[](#basic-routing)

Basic example for a GET request for home page.

```
\EvolutionPHP\Routing\Route::get('/', function (){
    return 'This is the home page.'
});

//Or you can use a controller class.
\EvolutionPHP\Routing\Route::get('/home', [HomeController::class, 'index']);

//Dispatch routes
\EvolutionPHP\Routing\Route::dispatch();
```

### Available Router Methods

[](#available-router-methods)

The router allows you to register routes that respond to any HTTP verb:

```
\EvolutionPHP\Routing\Route::get($uri, $callback);
\EvolutionPHP\Routing\Route::post($uri, $callback);
\EvolutionPHP\Routing\Route::put($uri, $callback);
\EvolutionPHP\Routing\Route::patch($uri, $callback);
\EvolutionPHP\Routing\Route::delete($uri, $callback);
\EvolutionPHP\Routing\Route::options($uri, $callback);
```

If you need to register a router that responds to multiple HTTP verbs:

```
\EvolutionPHP\Routing\Route::match(['get','post'], function (){
    // ...
})
```

Redirect Routes
---------------

[](#redirect-routes)

If you are defining a route that redirects to another URI, you may use the **Route::redirect** method

```
\EvolutionPHP\Routing\Route::redirect('/home', '/home-page');
```

Or, you may use the **Route::permanentRedirect** method to return a **301** status code:

```
\EvolutionPHP\Routing\Route::permanentRedirect('/home','/home-page');
```

Route parameters
----------------

[](#route-parameters)

### Required Parameters

[](#required-parameters)

For example, you may need to capture a user's ID from the URL. You may do so by defining route parameters:

```
\EvolutionPHP\Routing\Route::get('/user/{id}',function ($id){
    return 'User ID: '.$id;
});

\EvolutionPHP\Routing\Route::get('/post/{post}/comment/{comment}',function ($post_id, $comment_id){
    return 'Post ID: '.$post_id.' | Comment ID: '.$comment_id;
});
```

### Regular Expression Constraints

[](#regular-expression-constraints)

```
\EvolutionPHP\Routing\Route::get('/user/{id}',function ($id){
    return 'User ID: '.$id;
})->where('id', '[0-9]+')
```

Or you can use helpers:

```
\EvolutionPHP\Routing\Route::get('/user/{id}',function ($id){
    return 'User ID: '.$id;
})->whereNumber('id')

\EvolutionPHP\Routing\Route::get('/post/{title}',function ($title){
    return $title;
})->whereAlphaNumeric('title')
```

Router names
------------

[](#router-names)

You can assign names to routes

```
\EvolutionPHP\Routing\Route::get('/user/profile', function (){
    // ...
})->name('user_profile');
```

### Generating URL for a route using its name

[](#generating-url-for-a-route-using-its-name)

```
$url = \EvolutionPHP\Routing\Routing::generateURL('user_profile');
//Redirect route
\EvolutionPHP\Routing\Routing::redirect($url);
```

If the named route defines parameters, you may pass the parameters as the second argument to the route function.

```
\EvolutionPHP\Routing\Route::get('/user/{id}', function ($id){
    // ...
})->name('user_profile');

$url = \EvolutionPHP\Routing\Routing::generateURL('user_profile', ['id' => 5]);
```

### Get current route name

[](#get-current-route-name)

```
\EvolutionPHP\Routing\Routing::routeName();
```

Route Groups
------------

[](#route-groups)

### Controllers

[](#controllers)

If a group of routes all utilize the same controller, you may use the controller method to define the common controller for all of the routes within the group. Then, when defining the routes, you only need to provide the controller method that they invoke:

```
\EvolutionPHP\Routing\Route::controller(UserController::class)->group(function (){
    \EvolutionPHP\Routing\Route::get('/user/dashboard', 'dashboard');
    \EvolutionPHP\Routing\Route::get('/user/profile', 'profile');
});
```

### Route Prefixes

[](#route-prefixes)

The prefix method may be used to prefix each route in the group with a given URI. For example, you may want to prefix all route URIs within the group with admin:

```
\EvolutionPHP\Routing\Route::prefix('admin')->group(function (){
    \EvolutionPHP\Routing\Route::get('/users', function (){
        // Matches the "/admin/users" URL
    })
});
```

### Route Name Prefixes

[](#route-name-prefixes)

The name method may be used to prefix each route name in the group with a given string.

```
\EvolutionPHP\Routing\Route::namePrefix('admin')->group(function (){
    \EvolutionPHP\Routing\Route::get('/admin/users', function (){
        // Route assigned name "admin.users"
    })->name('users');
});
```

### Route Middleware

[](#route-middleware)

Example of a middleware

```
class UserAuth(){
    public function handle(\EvolutionPHP\HTTP\Request $request, Closure $next) {
        if(!$request->post('token')){
            \EvolutionPHP\Routing\Routing::redirect('/');
        }
        return $next($request);
    }
}
```

To use the middleware:

```
\EvolutionPHP\Routing\Route::middleware(UserAuth::class)->group(function (){
    \EvolutionPHP\Routing\Route::get('/user/dashboard', function (){
        return 'User dashboard.';
    });
\EvolutionPHP\Routing\Route::get('/user/profile', function (){
        return 'User user.';
    });
});
//or define a middleware for a single route
\EvolutionPHP\Routing\Route::get('/user/comments', function (){
    return 'User comments.'
})->withMiddleware(UserAuth::class);
```

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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

Unknown

Total

1

Last Release

546d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d5a42f2155ba37cd77c46f9e57c613e0c08394b5e2b59e8ff77e0d44adaf907?d=identicon)[EvolutionPHP](/maintainers/EvolutionPHP)

---

Top Contributors

[![aqpdev](https://avatars.githubusercontent.com/u/143758553?v=4)](https://github.com/aqpdev "aqpdev (2 commits)")[![EvolutionPHP](https://avatars.githubusercontent.com/u/106336615?v=4)](https://github.com/EvolutionPHP "EvolutionPHP (1 commits)")

---

Tags

phprouting

### Embed Badge

![Health badge](/badges/evolutionphp-routing/health.svg)

```
[![Health](https://phpackages.com/badges/evolutionphp-routing/health.svg)](https://phpackages.com/packages/evolutionphp-routing)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.9k556.2M21.5k](/packages/laravel-framework)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k257.3M12.4k](/packages/symfony-framework-bundle)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.9M535](/packages/pimcore-pimcore)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19467.3M1.9k](/packages/drupal-core)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M236](/packages/sulu-sulu)

PHPackages © 2026

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