Domanda

I am new to laravel framework and php so it is difficult for me to ask this. I want my php application to route to login page with any input through my route. For example, let's say my website is www.example.com and if the user tries to input www.example.com/xxxxx, I want the user to be directed to the default page which is www.example.com if there exists no listener in my route for xxxxx. I hope this makes sense. Any help will be appreciated. Thank you

È stato utile?

Soluzione

If you go down the page on the docs here, you should find a section talking about Route Parameters and Regular Expression Route Constraints. You can use this to achieve what you want like this:

//Make sure to place this as the bottom most route in your routes.php
Route::any('{anything}', function($anything)
{
     die('You can call a controller here and pass '.$anything.' or not.');

})->where('anything', '(.*)');

{anything} is a "route parameter", you can give the parameter any name you want, but it's the regular expression (.*) used with it in a where that helps you achieve this effect.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top