Skip to content

Config cache fails with "Your configuration files are not serializable" due to "ip_selector" #64

@dev-ramchander

Description

@dev-ramchander

image

When using the ipinfo configuration in Laravel 10 with a custom IP selector object, the php artisan config:cache command fails, throwing the error:

LogicException

Your configuration files are not serializable.

at vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:73

The root cause is the direct instantiation of CustomIPSelector in the configuration array, as shown

'ipinfo' => [
    'access_token' => env('IPINFO_SECRET'),
    'ip_selector' => new CustomIPSelector(),
    'filter' => false,
    'no_except' => true,
],

Steps to Reproduce:

  1. Define the configuration as above.
  2. Run php artisan config:cache.
  3. Observe the error:
LogicException
Your configuration files are not serializable.

Workaround Attempt:
Replacing the instantiation with the class name works for php artisan config:cache:

'ipinfo' => [
    'access_token' => env('IPINFO_SECRET'),
    'ip_selector' => App\Helpers\CustomIPSelector::class,
    'filter' => false,
    'no_except' => true,
],

However, this leads to another error when using the ipinfo library:

Call to a member function getIP() on string

This happens because the library directly uses the ip_selector configuration value without instantiating the class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions