Laravel redirect back using with not stored to session

Viewed 35

Hello i'm trying to redirect my controller back with build in function from laravel to store a message to html but it seem the with() function not stored the value i write, here is the code i have on controller side

return back()->with('Sign-in-error', 'Log in failled!, username or password may be wrong please try again');

and then i receive it at html like this:

@if (session()->has('Sign-in-error'))
        <div id="login-error-info" class="alert alert-errors alert-dismissible fade show d-flex justify-content-center" style="height: fit-content; width: fit-content; position: absolute; margin-left: 25%; margin-right: 25%; margin-top: 10px; width: 50%; left: 0; background-color: red; font-size: 15px; color: white;" role="alert">
        <small class="d-block text-center"> {{{ session('Sign-in-error') }}} </small>
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
@endif

<p>Sesion: {{{ session('Sign-in-error') == null ? 'no session found' : session('Sign-in-error') }}}</p>

i try to find similar problem from other but seem nothing can help with mine, any help will really appreciate. thanks

1 Answers

Try this :

return redirect()->back()->with('Sign-in-error', 'Log in failled!, username or password may be wrong please try again'); 

in blade file :

    @if (session()->has('Sign-in-error'))
        <div id="login-error-info" class="alert alert-errors alert-dismissible fade show d-flex justify-content-center" style="height: fit-content; width: fit-content; position: absolute; margin-left: 25%; margin-right: 25%; margin-top: 10px; width: 50%; left: 0; background-color: red; font-size: 15px; color: white;" role="alert">
        <small class="d-block text-center"> {{ session('Sign-in-error') }} </small>
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
@endif

<p>Sesion: {{ session('Sign-in-error') == null ? 'no session found' : session('Sign-in-error') }}</p>
Related