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

Naim's avatar
Level 3

Cannot serialize or unserialize PDO instances

Hi all,

I'm starting this topic because I have a problem with my new development app. I pushed it to Digital Ocean thanks to Forge.

I can access the login page as expected. But as soon as I login, I get this strange message, which I never met:

Whoops, looks like something went wrong.

1/1
PDOException in FileStore.php line 98:
You cannot serialize or unserialize PDO instances

in FileStore.php line 98
at PDO->__sleep()
at serialize(object(Builder)) in FileStore.php line 98
at FileStore->put('user_1', object(Builder), '0') in FileStore.php line 159
at FileStore->forever('user_1', object(Builder)) in Repository.php line 177
at Repository->forever('user_1', object(Builder)) in Repository.php line 232
at Repository->forever('user_1', object(Builder)) in Repository.php line 232
at Repository->rememberForever('user_1', object(Closure))
at call_user_func_array(array(object(Repository), 'rememberForever'), array('user_1', object(Closure))) in CacheManager.php line 310
at CacheManager->__call('rememberForever', array('user_1', object(Closure))) in compiled.php line 5662
at CacheManager->rememberForever('user_1', object(Closure)) in compiled.php line 5662
at Facade::__callStatic('rememberForever', array('user_1', object(Closure))) in ProfileComposer.php line 39
at Cache::rememberForever('user_1', object(Closure)) in ProfileComposer.php line 39
at ProfileComposer->compose(object(View))
at call_user_func_array(array(object(ProfileComposer), 'compose'), array(object(View))) in compiled.php line 13444
...

My app is running laravel 5.1. And I use the regular AuthController and PasswordController code to manage login.

Did anyone have this message. If so, how did you manage to solve it?

Thanks

EDIT

By looking closer at the error message, I wonder if it could be related to the cache. As 'forever' and 'rememberForever' are logged in this error message.

0 likes
1 reply
Naim's avatar
Level 3

My bad. I was calling this in a View Composer :

public function compose(View $view)
    {
        $userProfile = Cache::rememberForever('user_'.Auth::id(), function() {
            return $this->user->find(Auth::id())->with('profile');
        });

        $view->with('user', $userProfile);
    }

For some reason, I had to remove the "with('profile')" call . Still on the way to become a Laravel Jedi ...

Please or to participate in this conversation.