jeudi 14 juin 2018

Laravel 5.6: session()->push('variable') doesn't reach view until second refresh

I noticed that in Laravel 5.6, my session variable isn't passing to my middleware until the second page refresh.

Middleware: Let's say you have this middleware called ViewData that shares variables to the view.

public function handle($request, Closure $next) {

        $setHandle = session('setHandle')[0];

        $account = AccountUser::where('handle', '=', $setHandle)->first();
        view()->share('account', $account);

    return $next($request);

}

Controller: The Controller sets the setHandle session variable then returns a view:

public function add()
{   
    session()->forget('setHandle');
    session()->push('setHandle', $setHandle);
    return view('account.add');
}

Reference in my View My view will then have a reference to variables from this middleware.

      <a class="navbar-brand brand-logo text-light" href="{!! url('account/'.$account->whatever) !!}">{!! $account->whatever !!}</a>

The problem is the first return view is returned with the old setHandle variable, when I refresh again it returns the new account with the setHandle variable.

I thought it may have to do with where my middleware is set, but my viewData middleware is being set after the StartSession middleware, so I thought the session would be refreshed after the middleware is called.

\Illuminate\Session\Middleware\StartSession::class,
'App\Http\Middleware\ViewData',

Any help would be appreciated.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2JIJ64M
via IFTTT

Aucun commentaire:

Enregistrer un commentaire