ItSolutionStuff.com

How to Redirect Route with Querystring in Laravel?

By Hardik Savani • April 16, 2024
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: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to use OpenAI in Laravel?

Read Now →

Laravel Ajax DELETE Request Example Tutorial

Read Now →

How to Add Google Map in Laravel?

Read Now →

How to Get Last Month Data in Laravel?

Read Now →

Laravel Http Curl Delete Request Example

Read Now →

Laravel Create Custom Facade Class Example

Read Now →

Laravel Collection Implode Method Example

Read Now →

How to Check Request is Ajax or Not in Laravel?

Read Now →

How to Check Request Method is GET or POST in Laravel?

Read Now →

Laravel Repository Pattern Tutorial Example

Read Now →

Example of unionAll in Query Builder Laravel

Read Now →

Laravel Join with Subquery in Query Builder Example

Read Now →

How to Setup Cron Job in Laravel?

Read Now →