Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

[Bug] Ardent object not serializable #16

Closed
ghost opened this issue Feb 20, 2013 · 4 comments · Fixed by #20
Closed

[Bug] Ardent object not serializable #16

ghost opened this issue Feb 20, 2013 · 4 comments · Fixed by #20

Comments

@ghost
Copy link

ghost commented Feb 20, 2013

I noticed that when trying to serialize an Ardent model I get an error:
Serialization of 'Closure' is not allowed

Basically the cause is the purgeFilters property is being set to a Closure in the constructor.

Would be great if it can be fixed ;)

Cheers,

Bryan te Beek

@maximebeaudoin
Copy link

👍

@laravelbook
Copy link
Collaborator

Unfortunately, anonymous functions cannot be serialized in PHP. There are some (convoluted) workarounds.

As for serializing model objects I can think up a work-around: instead of de/serializing the original ardent class, derive a second object (i.e. "MyArdentModelSlice") which represents a subset of the base model class (attributes, rules, custom error messages etc.)

I'm keen to hear your thoughts on this issue.

@ghost
Copy link
Author

ghost commented Feb 25, 2013

My main point is that Eloquent models are serializable. So Ardent models should also be serializable otherwise basic laravel things like this won't work imho.

$users = Cache::remember('users', $minutes, function()
{
    return User::all();
});

@laravelbook
Copy link
Collaborator

@bryantebeek - Thanks for the elegant solution to the real problem! 👍
I've slightly modified your patch to prevent accidental re-initialization of the filters array: 49395b2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants