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

davy_yg's avatar
Level 27

Passing Session

Hello,

I have been trying to pass session and unsuccessfuly:

LoginController.php

	    ...
		 Session::put('success', 'Welcome Aboard. Please Login!');

  		  return redirect('login');
		}

StoreController.php

	    public function login()
       {
        Session::pull('success', 'Welcome Aboard. Please Login!');

    	return view('store.login');
	    }

login.blade.php

		@if ($message = Session::get('success'))
				<div class="alert alert-success alert-block">
    					<button type="button" class="close" data-dismiss="alert">×</button>	
       				<strong>{{ $message }}</strong>
				</div>
		@endif

In the login.blade.php the success message is not popping out!

0 likes
6 replies
tykus's avatar

What do you think this is doing?

Session::pull('success', 'Welcome Aboard. Please Login!');
Sinnbeck's avatar

pull deletes it. You use it to assign it to a variable

The pull method will retrieve and delete an item from the session in a single statement:

For example

$sucessInfo = Session::pull('success', 'Welcome Aboard. Please Login!');
SilenceBringer's avatar

@davy_yg check it here https://laravel.com/docs/8.x/session#retrieving-deleting-an-item

Your code

Session::pull('success', 'Welcome Aboard. Please Login!');

returns the value from session, but you do not assign it to any variable. So, it's just missing

For your case I can recommend to look at flashing data https://laravel.com/docs/8.x/session#flash-data

Session::flash('success', 'Welcome Aboard. Please Login!');

Then remove this line Session::pull('success', 'Welcome Aboard. Please Login!'); from controller, and in blade:

		@if (Session::has('success'))
				<div class="alert alert-success alert-block">
    					<button type="button" class="close" data-dismiss="alert">×</button>	
       				<strong>{{ Session::get('success') }}</strong>
				</div>
		@endif

after the first displaying success will be removed from session automatically (it's how flash works)

tykus's avatar
tykus
Best Answer
Level 104

It removes the success key from the Session; then you later check for the key, it's gone.

public function login()
{
    return view('store.login');
}
@if ($message = Session::pull('success'))
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>	
        <strong>{{ $message }}</strong>
    </div>
@endif

If the only time you want to display the message is the next request; then flash it to the Session.

1 like
MohamedTammam's avatar

You need to use put method

Session::put('success', 'Welcome Aboard. Please Login!');

From the docs

The pull method will retrieve and delete an item from the session in a single statement:

Please or to participate in this conversation.