Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed property App\Settings\GeneralSettings::$name must not be accessed before initialization #18

Closed
elmarzouguidev opened this issue Dec 25, 2020 · 7 comments

Comments

@elmarzouguidev
Copy link
Contributor

Typed property App\Settings\GeneralSettings::$name must not be accessed before initialization

I got this problem when I use this settings Class in some different namespace

@amrography
Copy link

Make sure you have $name property as public with your desired type in target setting class

namespace App\Settings;

use Spatie\LaravelSettings\Settings;

class GeneralSettings extends Settings
{
    public string $name; // <-- You need to have this line

    public static function group(): string
    {
        return 'general';
    }
}

@rubenvanassche
Copy link
Member

@devscript-abdo, did @amrography solution solve the problem? If not, make sure you've migrated each property within your settings class.

@elmarzouguidev
Copy link
Contributor Author

@rubenvanassche problem solved by define a default value for the $name :
public $name = 'xyz';

@amrshakya
Copy link

@devscript-abdo @rubenvanassche I'm having the same issue getting

Typed property App\Settings\AdminSetting::$expired_payin_limit_notify must not be accessed before initialization

<?php

namespace App\Settings;

use Spatie\LaravelSettings\Settings;

class AdminSetting extends Settings
{
    public array $white_lists;

    public int $expired_payin_limit_notify;   //  <---  this has been defined
    public static function group(): string
    {
        return 'admin';
    }
}

@rubenvanassche
Copy link
Member

There must be something wrong with mapping the properties from your database onto your settings class. Could you please check for typo's. We do unregister all public properties when the class is constructed so they can be loaded when required. That's why the exception says that the property is not initialized.

@amrshakya
Copy link

@rubenvanassche After i re-updated the value for the setting it issue seems to be fixed. Thanks.

@marcuschristiansen
Copy link

Make sure, if your settings are cached, you clear your cache.

php artisan settings:clear-cache

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

No branches or pull requests

5 participants