Best Practice for HTTP Redirect

Posted 1 year ago by Tipoff

I'm reading the documentation on redirects (https://laravel.com/docs/5.4/redirects), but having some trouble setting one up the way I want. I have a quotes database table with an id column that begins incrementing at 1,000,000 so there will always be 7 digit id numbers for them. I want people to visit mywebsite.com/1000000 and be redirected to mywebsite.com/quotes/quotations/1000000 and have tried the following to no avail:

Route::get('quotes/quotations/{quote}', '[email protected]');

Route::get('{quote}', function () {
    return redirect()->action(
    '[email protected]', ['id' => {quote}]

I have also tried things like:

Route::get('quotes/quotations/{quote}', '[email protected]');

Route::get('{quote}', function () {
    return redirect('quotes/quotations/{quote}');

My main route works, but both attempts at the redirect are failing. I think it is not passing along the prior {quote} id value, but I can't find an example with this to fix it. Any help and advice on the best practice for implementing this would be appreciated. Thanks

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.