0
0
0ldn0mad2019-08-02 14:16:38
Laravel
0ldn0mad, 2019-08-02 14:16:38

How to validate parameters in Route LARAVEL with regular expression?

Good afternoon.
Can you please tell me how to check a parameter in a Route with a pattern closure using a regular expression:

Route::get('user/{name}', function ($name) {
  die("User: {$name}");
}) -> where ('name', '[\S]+');

Required parameters must contain one of the following values: 'name', 'surname' or 'age'.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konata Izumi, 2019-08-02
@0ldn0mad

Can be stupidly overkill

Route::get('user/{name}', function ($name) {
  die("User: {$name}");
})->where('name', 'name|surname|age');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question