Search code examples
phpgetrouteslaravel-5any

Laravel 5 Route (:any)


Hello I am new to laravel and i'm learning with a video tutorial that is with version 4 which for the Routes that doesn't exists on a url shortener project he wrote the code like below

Route::get('(:any)', function(){
    return 'some url';
});

but it doesn't work in lar 5.
ok, so what am i trying to do of course him!
when i shorten the url i give the users a link with href attr of this

<a href="laravel.url.dev/{{ $shortened }}">laravel.url.dev/{{ $shortened }}</a>

note that the var is url saved in db for that url which user inputed but now when user clicks the url i want to redirect them to the saved url in db but what if they gave a url that is not in my db so it will be messed up! but my problem is i can not detect the url not only i gave to them but also they give me
for example laravel.url.dev/asdf
thanks in advance ;)


Solution

  • What exactly are you trying to achieve here?

    Here is the same code rewritten for Laravel 5 to always return "some url"

    Route::get("{any}", function() {
        return "some url";
    });