Zhenya40
Zhenya40

Reputation: 21

Routing in Laravel with redirects

I am trying to deal with the routing in Laravel. How can I do the following?

If the user dials the number (3 to 11) here:

The numbers may include a dash between them, as well as '1' at the beginning (this dialing code).

It is necessary to remove the dash then if the 11 numbers, need to remove '1' in beginning.

We redirect it depending on the number of digits dialed

My routes (While excluding a dash):

Route :: get ( 'area/{phone}', 'Controller@phone') -> where ([ 'phone' => '[0-9]{3,11}']);
Route :: get ( 'phone/{phone}', 'Controller@phone') -> where ([ 'phone' => '[0-9]{3,11}']);

The controller performs a dash removal, cropping unwanted numbers, cropping '1' if 11 digits and then redirect to /phone/, /area/.

But after the redirect, routes.php starts again and cycle becomes infinite.

What can I do? Maybe there is another way?

Upvotes: 1

Views: 135

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163768

You want to use standard routes with parameters and then validate input. If input is incorrect, you're redirecting to a 404 error page.

Upvotes: 1

Related Questions