Redirect Users Using To_route() Helper In Laravel 9.x

Hello Artisan,

Laravel 9.x version released a new helper to_route() to redirect users. You know that, we can redirect user with redirect() and route() helper function, but from Laravel 9. version, we can also use the to_route() helper to redirect users.

Normally we redirect users after a form submits or any action in Laravel. So in this example, we will see how we can redirect user using to_route() helper function. You can see below example code:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index(Request $request, $page = 1)
        $users = User::get();
        return to_route("home");


It will redirect users to the home page. 


Read also: Laravel Web Socket Example with Event Broadcasting


Hope it can help you.


#laravel #laravel-9x