Redirect to another URL

  • STEP

    Redirect to a URL

    1. Sometimes you want to redirect to another URL instead of return view()

    
                      return redirect('/companies/create');
                      

    Redirect to previous page

    2 Sometimes you may wish to redirect the user to their previous location

    
                      return back()
                      

    Redirecting To Controller Actions

    
    
                      use App\Http\Controllers\HomeController;
    
                      ......
                      .......
    
                      return redirect()->action([HomeController::class, 'index']);
                      

    Redirect with parameters

    
                      return redirect()->action(
                          [UserController::class, 'profile'], ['id' => 1]
                      );
                      

    Redirecting With Flashed Session Data

    
                      return redirect('/dashboard')->with('status', 'Profile updated!');
                      

    Get the redirected data in the view

    
                      @if (session('status'))
                          <div class="alert alert-success">
                          {{ session('status') }}
                          </div>
                      @endif