Category: Laravel

With routing you can specify Route::get(‘projects/{project_id}’, ‘ProjectController@show’); but what if you want project_id to be strictly a number?
To achieve that, you can put where() condition on any Route statement, and use regular expressions for specifying data pattern.
Not only that, you can specify that some variable name would always follow a certain pattern.
Like, for example, you want project_id in all routes to be integer.
Then you do this in app/Providers/RouteServiceProvider.php:public function boot() { Route::pattern('project_id', '[0-9]+'); parent::boot(); }

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Community Partners