How to Redirect Route with Querystring in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hey Artisan,

Now, let's see post of laravel redirect with query string. This tutorial will give you a simple example of laravel redirect with message. Here you will learn laravel redirect with parameters. We will use redirect back with params laravel. Here, Create a basic example of laravel redirect route with parameters.

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

Most of the time, when working on the back-end, we need to redirect routes or URLs from the controller while passing query string parameters. Laravel provides a simple way to accomplish this. In the following example, you can see how this can be done.

In the example below, we have added the index() function to handle a route. In this function, we redirect to the "home" route with two parameters passed as query strings, such as "id" and "itemid". As a result, the URL will look like this:

http://example.com/home?id=2&itemid=3

And controller function will be this way:

Example:

namespace App\Http\Controllers;


use Illuminate\Http\Request;

use App\View;


class HomeController extends Controller

{


public function index()

{


$viewer = View::all();


return redirect()->route('home',['id'=>2,'itemid'=>3])

->with('info','We are in home back.');

}


}

I hope it can help you..

Tags :
Shares