Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

WAL30's avatar
Level 1

Laravel 8 session status issue

Hello,

Can someone tell me or help me with this issue ? In laravel 8 alerts do not work.

@if (session('status')) {{ session('status') }} @endif

0 likes
16 replies
Nakov's avatar

Good question, not enough evidence :)

What do you use as a Session driver? In your .env file you have SESSION_DRIVER=file ?

Then what do you return from your controller?

...
return back()->with('status', 'Some message that should show');

do you have that code in your main layout or the view file that you are expecting the session message to show? I can go on and on, you gave no reason on why that won't work :)

1 like
WAL30's avatar
Level 1

@Nakov Thank you for answering me.

I have implemented a reset password, this is my email.blade.php

/

{{ __('Reset password') }}
            <div class="card-body">
                @if (session('status'))
                    <div class="alert alert-success" role="alert">
                        {{ session('status') }}
                    </div>
                @endif

                <form method="POST" action="{{ route('password.email') }}">
                    @csrf

                    <div class="form-group row">
                        <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('Adresa ta de email') }}</label>

                        <div class="col-md-6">
                            <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="form-group row mb-0">
                        <div class="col-md-6 offset-md-4">
                            <button type="submit" class="btn btn-primary">
                                {{ __('Trimite-mi link-ul') }}
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

When I try to reset my password, this message should appear, but nothing happens, I only get an email to reset the pass

'sent' => 'We have emailed your password reset link!',

Yes in env I have SESSION_DRIVER=file

WAL30's avatar
Level 1

@Snapey I am not sure I understand, I use a prebuilt reset pass from laravel, I only added SMTP settings. Where should I put this, if is prebuilt?

return back()->with('status', 'Some message that should show');

I think it should take it automatically from resources/lang/en/passwords.php

'reset' => 'Your password has been reset!',
'sent' => 'We have emailed your password reset link!',
'throttled' => 'Please wait before retrying.',
'token' => 'This password reset token is invalid.',
'user' => "We can't find a user with that email address.",

Should take this line 'sent' => 'We have emailed your password reset link!',

What did I do wrong?

Nakov's avatar

@WAL30 Have you changed the redirect path after you reset your password? You are right that the framework returns a message with status key in the session, but if you are redirected to another page, you won't see it from the view you are adding it to.

That's why I said, if you have a main layout.blade.php file, add it right below the body tag so you can test if it does show or not. By default the ResetPasswordController I believe it has this:

protected $redirectTo = '/home';

so whichever view loads your home route, that's where you'll have to add that session check.

WAL30's avatar
Level 1

@Nakov no, is not from there. It only works if I set it like that Session::put('status','Some text');

I am not sure why...

Nakov's avatar

@WAL30 I believe you don't understand me. You've got to know which page loads next after successful resetting of the password and do the session('status') check there, because the blade view that you've put that check on is not returned having that flash variable in.

I know the reason why Session::put('status','Some text'); works.. that's because once you put it in the Session it stays there until you remove it manually or the session expires.

But when used ->with on a response, that puts the variable into a so called flash session which lasts for one request. So you've got to know where you are redirecting after a successful resetting in order to display the session('status') there.

I hope you understand what I am saying.

WAL30's avatar
Level 1

@Nakov Yes man I understand. There is no redirection for this page recovery password, it stays on the page after I click to send me the link for recovering the password.

It stays on this page but the message does not appear.

Snapey's avatar

@WAL30 thats not scaffolding. Scaffolding is Laravel UI, Jetstream or something else.

Nakov's avatar

@WAL30 You sure you don't have any additional middleware that you created and you've applied it to your routes? The only explanation for this is that multiple requests are happening.. so open your browser developer tools -> network tab, clear it before you try, and see if there is only one post request when you submit and only one get request that happens except the script/images requests, the back-end requests are just two.

You should see one POST request to email and one GET to reset. Tried it myself now I do see: https://snipboard.io/SGVDq2.jpg

Make sure you remove the styling from the message too, just in case your CSS is broken on that page.

Nakov's avatar

@WAL30 if it was a public project I would try it and let you know, otherwise I am out of ideas. Try the same on another page and see if it works.

You still have different styling on this page as far as I can see. So I would just try using the facade as a last thing.. anywhere on the page just place {{ Session::get('status', 'testing') }} if you can't even see testing when you first load the page, that means that there is a styling issue on your page. If you see that, and then when you submit you still see testing back, then there is a session issue. So maybe try another browser, or clean your cache php artisan cache:clear ..

WAL30's avatar
Level 1

@Nakov thanks.

Can you tell me please what version of bootstrap do you use to take this test ? Maybe I am not using the correct version with laravel 8.

Something is very strange if I use {{ Session::put('status', 'testing') }} and then {{ Session::get('status', 'testing') }} it works because it is in Session like you said, but not working with {{ Session::flush('status', 'testing') }} or with().

I think something is not fine from the beginning of this project, this Is my web.php content

Route::get('/', [FrontendController::class, 'index']);

Route::middleware(['auth'])->group(function () {
    
    Route::get('checkout/{id}', [CheckoutController::class, 'index']);
    Route::post('checkout', [CheckoutController::class, 'stripePost'])->name('stripe.post');    

    Route::get('my-orders', [UserController::class, 'index']);
    Route::get('view-order/{id}', [UserController::class, 'view']);
    
});


 Auth::routes();

 Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::middleware(['auth','isAdmin'])->group(function () {

    Route::get('/dashboard', 'Admin\FrontendController@index')->name('dashboard');
    
 
    Route::get('products', [ProductController::class, 'index']);
    Route::get('add-product', [ProductController::class, 'add']);
    Route::post('insert-product', [ProductController::class, 'insert']);

    Route::get('edit-product/{id}', [ProductController::class, 'edit']);
    Route::put('update-product/{id}', [ProductController::class, 'update']);
    Route::get('delete-product/{id}', [ProductController::class, 'deleteProd']);

    Route::get('orders', [OrderController::class, 'index']);
    Route::get('admin/view-order/{id}', [OrderController::class, 'view']);
    Route::put('update-order/{id}', [OrderController::class, 'update']);
    Route::get('order-history', [OrderController::class, 'orderhistory']);

    Route::get('users', [MembersController::class, 'users']);
    Route::get('view-user/{id}', [MembersController::class, 'view']);

 });

I will publish it on GitHub

themarketive's avatar

Did you solved this ? Because I have the exact problem, only in laravel 5.8..

Please or to participate in this conversation.