Skip to content
Advertisement

Laravel Livewire error “must not be accessed before initialization”

I try to using Livewire Binding Directly To Model Properties, and i get this error, Anyone help please ? Thank in advance.

Typed property AppHttpLivewireV2SettingsLocations::$country must not be accessed before initialization

JavaScript

Advertisement

Answer

When you define the type of a variable in PHP, you need to provide it a default value.

If your component is creating a Country, you can set it to an empty Country in the mount function:

JavaScript

Alternatively set the public Country $country to be an existing Country.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement