
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:
- Define the configuration as above.
- Run
php artisan config:cache.
- 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.
When using the
ipinfoconfiguration inLaravel 10with a custom IP selector object, thephp artisan config:cachecommand fails, throwing the error:The root cause is the direct instantiation of
CustomIPSelectorin the configuration array, as shownSteps to Reproduce:
php artisan config:cache.Workaround Attempt:
Replacing the instantiation with the class name works for
php artisan config:cache:However, this leads to another error when using the
ipinfolibrary:This happens because the library directly uses the
ip_selectorconfiguration value without instantiating the class.