Tuesday, January 25, 2022

[FIXED] No session variables show up in view - Laravel 5.1

Issue

I am trying to display errors on my login page using the Session::flash() method in Laravel 5.1.

In my view I am using:

@if($errors->has())
    <div class="alert alert-danger">
        @foreach ($errors->all() as $error)
            <div>{{ $error }}</div>
        @endforeach
    </div>
@endif

And in my controller:

return Redirect::route('login')->withErrors($validator)->withInput();

  1. I am not getting anything from the Input::old() method when getting redirected with errors to this page.

  2. The $errors variable is empty on the reload.

If I dd($validator); right before the return Redirect::route..., the $validator has data in it:

enter image description here

But when the page loads, nothing happens.

I can try Session::put but still, nothing happens when getting the view.

What could be wrong? Is there maybe something in composer or php artisan that may be able to reset this issue?


Solution

To anyone that has this problem, how I solved it was changing the .env file from SESSION_DRIVER=array to SESSION_DRIVER=file



Answered By - Haring10

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.