Support the ongoing development of Laravel.io →
Session Eloquent

Problem: Model events (Model::saving, etc...) don't work anymore after putting an instance of the model into a session.

I have an Order model. I can use it in different controllers all over my app and the Model::saving event wil fire upon calling $order->save(). Once I load an instance of Order (Model) into the active Session, model events for Order (Model) will stop working (i.e. Model::saving will not get fired any more anywhere in the app for the Order model). The same happens for any other model put into the active Session. If I remove the Order model from the Session (using Session::forget), events will start working again for that Model.

Files and more details can be found here in the error log description:

http://help.laravel.io/7962c42a6ee4e1f335a06e76925c682ffe40c984

Seems Session is somehow calling the Boot() function for my models and by doing it messes up the Closure callback to Model::saving() thus preventing any subsequent calls to Model::saving().

This is very annoying and doesn't seem like expected behavior? Does anyone know how to fix this?

(Hacky workaround would be to temp remove the model from the Session and placing it back but that's no solution)

Last updated 3 years ago.
0

Apparently using an observer on the model will also fix the problem. The observer saving function will fire whether or not there is a model instance in Session. Yet this is just another workaround.

Order::observe(new OrderObserver);
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.