Make Jobs MultiStore Compatible

By default, every job that executes on NexoPOS 4x asynchronously doesn't care much about multistore. The reason for this is that while models are being serialized, only the identifier is used for fetching the original model.

The issue here is that, if we're using a model that uses a dynamic table property, we won't be able to instruct Laravel to fetch the model from that specific table. From NexoPOS 4.8.3, it's possible to make jobs compatible with the multistore extension.


The trait NsDispatchable ensures the multistore module is able to serialize eloquent models and unserialize them before the handle method fires, through Job middleware. Typically, you'll define your jobs like this.

Once the trait is added to your job, you need to call "prepareSerialization" so that a proper event will notify the multistore module that the job is about to be fired. At that time, the multistore module will serialize all models.

The trait NsDispatchable already ships a middleware that will execute an even when the job is about to be fired asynchronously. At that moment, the multistore module will unserialize the models and create fetches new instances.