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

MirkoKlefker's avatar

Session::put and get incompatible with Laravel 10

Hi, I upgraded my Project from laravel 6 to 9 without any problem. Now from Laravel 9 to 10 I have a Problem with the Session::put and get.

In Laravel 9 it was possible to use Session::put($e->getErrors()); and Session::get($errorKey)); So it was possible to use it with only a Key without a Value.

Why is this not possible with Laravel 10 and why is there no note about it in the Upgrade guide?

Im running PHP 8.1.

0 likes
8 replies
vincent15000's avatar

I'm running PHP 8.1 and Laravel 10 and I have no problem with the sessions.

What error message do you get ?

Snapey's avatar

You should just use a key like expected, not leave it to chance

1 like
kokoshneta's avatar

@Snapey It seems they’re trying to store an object, using the individual object properties as keys. Not sure if that’s wise, but it is at least not quite leaving it just to chance. It’s just not possible with an object, has to be an array.

1 like
kokoshneta's avatar
Level 27

The Session::put() method has not changed between 9.x and 10.x. It is still possible to use it with only one parameter, but that parameter must then be an array. Note: an actual array, not just an object that is traversable like an array.

Your $results variable is a PendingDispatch object, not an array, so it won’t work. It doesn’t work in Laravel 9 either. The put() method uses is_array() to check if its first parameter ($key) is an array, and if it isn’t, it redefines $key to be an array with the original value of $key as the array key. Since an object is not a valid value for an array key, you get the error you’re seeing.

If you cast your object to an array, however, it should work:

if (Request::has('link')) {
	Session::put((array) $results);
}
1 like

Please or to participate in this conversation.