Support the ongoing development of Laravel.io →
Security Requests

Global Regex Patterns do not work.

Laravel 5.0 documentation states that global patterns should be put on the boot() function of RouteServiceProvider.

	public function boot(Router $router)
	{
		parent::boot($router);
		$router->pattern(['id' => '[0-9]+']);		
	}

But they seem to be ignored and thus a GET /test/foo doesn't throw an exception.

It only works if I place it on the route:

     Route::get('/test/{id}', function($id) {
          return $id;
     })->where('id' => '[0-9+]');
Last updated 3 years ago.
0
Solution

UPDATE: I realize I have to register the pattern before the call to the parent's boot.

    public function boot(Router $router)
    {
        $router->pattern(['id' => '[0-9]+']);       
        parent::boot($router);
    }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

miagg miagg Joined 26 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.