YouTube Icon

Code Playground.

How to use Regular Expression Constraints Route in Laravel 5.7

CFG

How to use Regular Expression Constraints Route in Laravel 5.7

Basic Limitations of Speech Route use system where. The where method accepts the parameter name and a regular expression that determines the validity of the parameter.

Let see in below example.

Route::get('user/{name}', function ($name) {
    //
})->where('name', '[A-Za-z]+');

Route::get('user/{user_id}', function ($user_id) {
    //
})->where('user_id', '[0-9]+');

Route::get('user/{user_id}/{name}', function ($user_id, $name) {
    //
})->where(['user_id' => '[0-9]+', 'name' => '[a-z]+']);

And if you like this tutorials please share it with your friends via Email or Social Media.




CFG