Slash missing in redirecting URL

Viewed 95
Route::get('reviews', 'ReviewController@single')->name('reviews');
// redirect to the new listing
        return redirect()->route('reviews', [$uri]);

I'm trying to redirect the URL when submitted. But for example when I submit https://example.com/ the URL returns as https://example.com/reviews?example.net I want it to be https://example.com/reviews/example.net (My site: https://example.com/ Submitted URL: https://example.net/) How can I do this? Thanks for helping!

2 Answers

Change your route declaration like below

Route::get('reviews/{uri}', 'ReviewController@single')->name('reviews');

And in the controller function, you can redirect to reviews route by using

public function foo()
{

    ...

    $uri = 'https://example.net';
    return redirect()->route('reviews', $uri);
}

Your route should be:

Route::get('reviews/{uri}', 'ReviewController@single')->name('reviews');

and on controller:

$uri = 'https://example.net';
return redirect()->route('reviews', $uri);

You can learn about parameters in Laravel route here:

https://laravel.com/docs/8.x/routing#required-parameters

Related