0

I have the following code, In which i am checking for error.

<div class="alert alert-danger {{ (\Session::has('message') && \Session::get('form', 'login') == 'login') ? '' : 'display-hide' }}">
    <button class="close" data-close="alert"></button>
    <span>
        {!! \Session::has('message') ? \Session::get('message') : 'Please correct your fields.' !!}
    </span>
</div>

On the controller side i have :

return redirect()
        ->back()
        ->with('message', 'Incorrect email or password.')
        ->with('form', 'login')
        ->withInput(\Input::except('password'));

The thing is that the message is not showing there.

Just the page refreshes and no message comes up.

Any idea ? Am i missing something ?

3 Answers 3

1

Simply on your view use \Session::pull('message') instead of \Session::get('message').

It is that simple .

Sign up to request clarification or add additional context in comments.

Comments

0

In your Controller

return redirect()
        ->back()
        ->with('message', 'Incorrect email or password.')
        ->with('form', 'login')
        ->withInput(\Input::except('password'));

And in your View

@if(Session::has('message')  && Session::has('form'))
<div class="alert alert-dismissable alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{!! Session::get('message') !!}
</div>
</span>
@endif

Note : You can have your own html in the condition, throw your message in your way and modify condition according to your need.

3 Comments

What are the changes ? plz comment at the changes
I am not clear with the user's html, So i have put the conditions openly like @if(Session::has('message') && Session::has('form'))
@sulthanAllaudeen Sorry for late replying...its still not working.
0

As the laravel 5.2 documentation says

<div class="alert alert-danger {{ (session('message') && session('form') === 'login') ? '' : 'display-hide' }}">
    <button class="close" data-close="alert"></button>
    <span>
        {!! session('message') ? session('message') : 'Please correct your fields.' !!}
    </span>
</div>

                        //OR

return redirect()
    ->back()
    ->with('message', 'Incorrect email or password.')
    ->with('form', 'login')
    ->with('classType', 'display-hide')
    ->withInput(\Input::except('password'));



<div class="alert alert-danger {{ session('classType') or '' }}">
    <button class="close" data-close="alert"></button>
    <span>
        {{ session('message') or 'Please correct your fields.' }}
    </span>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.