How to Redirect Route with Query String in Laravel?
This tutorial is for How to Redirect Routes with Query String in Laravel. We require redirecting the route or URL from the controller with the passed query string parameter. Laravel default provides a redirect() helper. redirect() helper provides a method route for redirecting the named route. In Bellow’s example, the cart() function for the route handler. this function redirects the home route with 2 parameters as query strings like id and product_id, so the URL will be like this way:
http://devnote.in/home?id=7&product_id=9
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Product;
class HomeController extends Controller
{
public function cart()
{
$products = Product::all();
return redirect()->route('home',['id'=>7,'product_id'=>9])->with('success','Redirect home page.');
}
}