How to make redirect with $_GET parameter laravel?

kontol-mabur-1

May 4th, 2017 04:10 PM

How to make redirect url after user successfully logged in but on dynamic route for example

User login with url domain.com/login?next=/next/route << url encoded ,

thrn user redirect to /next/route route??

devdojo

May 4th, 2017 04:26 PM

After using the default Laravel Authentication you should have a file located at app/Http/Controllers/Auth/LoginController.php, if you do not create this new controller:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use App\Http\Controllers\Auth\ActivationService;

class LoginController extends Controller
{
  public function __construct(ActivationService $activationService)
  {
    $this->middleware('guest', ['except' => 'logout']);
    $this->activationService = $activationService;
  }
}

Then you need to add a new method in that controller like so:

protected function authenticated(Request $request, $user)
{
  return redirect($request->get('next'));
}

Then inside of your login form you will need to have the following hidden input:

<input type="hidden" name="next" value="{{ {{ app('request')->input('next') }} }}">

Hope that helps :)

Thanks.

kontol-mabur-1

Jul 14th, 2017 06:41 PM

thanks tony

francis-mendez

Aug 27th, 2019 02:31 AM

Like this post Nice