Route::get('user/{id}/{name}/{age?}', function ($id, $name, $age = 'noage') { return 'User '.$id.' '.$name.' '.$age; }); 

Trying to set a global limit for id in RouteServiceProvider.php Now it has the following content:

 public function boot() { $this->setRootControllerNamespace(); if ($this->app->routesAreCached()) { $this->loadCachedRoutes(); } else { $this->loadRoutes(); $this->app->booted(function () { $this->app['router']->getRoutes()->refreshNameLookups(); $this->app['router']->getRoutes()->refreshActionLookups(); }); } } 

I can’t add Route::pattern('id', '[0-9]+') (as in the documentation), it gives the error Class 'Illuminate\Foundation\Support\Providers\Route' not found

What am I doing wrong? Version 5.5.58

  • Route :: get ('user / {id} / {name} / {age?}', Function ($ id, $ name, $ age = 'noage') {return 'User'. $ Id. ''. $ name. ''. $ age;}) -> where ('id', [0-9] +); - Orange_shadow
  • and if so: \Route::pattern('id', '[0-9]+') - P. Fateev
  • @ P.Fateev, thanks - sergaunt

0