laravel - login redirect loses the url hash laravel - login redirect loses the url hash laravel laravel

laravel - login redirect loses the url hash


Thanks to Mruf direction, I managed to get to the bottom of this.Not sure it is the best implementation, but it seems to be working.

Basically, I insert the hash value in the form as Mruf suggested, and then extended the handleUserWasAuthenticated function in AuthController

login.blade.php

<script type="text/javascript" >  $( document ).ready(function() {    $('.urlHash').val(window.location.hash);  });</script><form id="login-form" role="form" method="POST" action="{{ url('/login') }}">  <input type="hidden" class="form-control urlHash" name="urlHash" value="">  ....</form>

AuthController.php

protected function handleUserWasAuthenticated(Request $request, $throttles){    if ($throttles) {        $this->clearLoginAttempts($request);    }    if (method_exists($this, 'authenticated')) {        return $this->authenticated($request, Auth::guard($this->getGuard())->user());    }    // old code: return redirect()->intended($this->redirectPath());    $newRequest = redirect()->intended($this->redirectPath());    $newRequest->setTargetUrl($newRequest->getTargetUrl() . $request->urlHash);    return $newRequest;}


A simple JavaScript would do the trick:

$("#login-form").submit(function(){    e.preventDefault();    $(this).append("<input type='hidden' name='hash' value='"+window.location.hash+"'");    $(this).submit();});

Now you can access the hash within your request object

function controllerAction(Request $request){    $hash = $request->get("hash");    // Parse Hash    ....    // Redirect to somewhere    ....}