How to Redirect Route with Querystring in 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..
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to use OpenAI in Laravel?
- Laravel Ajax DELETE Request Example Tutorial
- How to Add Google Map in Laravel?
- How to Get Last Month Data in Laravel?
- Laravel Http Curl Delete Request Example
- Laravel Create Custom Facade Class Example
- Laravel Collection Implode Method Example
- How to Check Request is Ajax or Not in Laravel?
- How to Check Request Method is GET or POST in Laravel?
- Laravel Repository Pattern Tutorial Example
- Example of unionAll in Query Builder Laravel
- Laravel Join with Subquery in Query Builder Example
- How to Setup Cron Job in Laravel?