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

thesimons's avatar

Caching / putting in the session a complex object

Hello,

I'm working with a complex object (RocketGate gateway) that can't be serialised.

I have a checkout made in 3 steps and spread hover 3 different Jobs. The ideally the object should be stored in the session and in each step. Actually I'm simply re-building the object at each step. It works but it has some problems that won't describe in details cause it's part of behaviour of this component.

Long story short: is there a way in Laravel to store somewhere a complex object without serialising it?

Thanks, Simon

0 likes
5 replies
Tray2's avatar

I would store it in the database, that would give you the freedom to do basically anything with it.

Tray2's avatar

@thesimons If it is data, then you can store it in the DB, you don't really need to make an object of it,

Glukinho's avatar

is there a way in Laravel to store somewhere a complex object without serialising it

Yes, in memory as PHP native object through all it's lifecycle. Do you really need to process asynchronously in several jobs? Can it all be handled in one sync job within one request?

martinbean's avatar

Long story short: is there a way in Laravel to store somewhere a complex object without serialising it?

@thesimons How are you expecting Laravel to “store” your object if you don‘t serialise it in some form?

If you need an object across multiple jobs then a session is not the answer, as sessions are for HTTP requests; not CLI processes like queues. So, you’re either going to need to save this “object” to the database, disk, or cache.

Please or to participate in this conversation.