spatie/laravel-settings

Use Illuminate\Database\Eloquent\Casts\Json if possible is Broken

Closed this issue · 2 comments

Hi, just for information for this case, the setting that contains nested array, the lowest array casted as object and not array

https://github.com/spatie/laravel-settings/releases/tag/3.2.2

First of, thank you for this great package.

This is a breaking change in our application too. We have instances where we would access the underlying values as an array, but this is now broken because those are returned as stdClass.

// Before 3.2.2
Astrogoat\Promobar\Settings\PromobarSettings {#4506 ▼
  -mapper: Spatie\LaravelSettings\SettingsMapper {#2351 ▶}
  -config: Spatie\LaravelSettings\SettingsConfig {[#4669 ▶](https://helixsleep.test/#sf-dump-521562539-ref24669)}
  -loaded: true
  -configInitialized: true
  #originalValues: Illuminate\Support\Collection {#4437 ▶}
  +payload: array:11 [▶]
  payload: array:11 [▼ // <-- Array
    "type" => "zaius"
    "button" => "<div><strong>VIEW OFFER*</strong></div>"
    "text_color" => "#ffffff"
    "padding_top" => "12"
    "content_mobile" => "<div>25% Off Sitewide + FREE Bundle! Ends 12/3</div>"
    "padding_bottom" => "12"
    "content_desktop" => "<div>🎁 Cyber Monday Sale! 25% OFF SITEWIDE + FREE Bundle With All Mattress Purchases ($330+ Value)! Offer Ends 12/3✨</div>"
    "background_color" => "#af295c"
    "zaius_content_id" => "2021__fourth_of_july__top_bar_pop_up_2021_-_fourth_of_july_-_top_bar_pop_up_2021_-_fourth_of_july_-_top_bar_pop_up_web_modal"
    "center_align_content" => true
    "countdown_timer_enabled" => false
  ]
  enabled: true
}
// After 3.2.2
Astrogoat\Promobar\Settings\PromobarSettings {#4506 ▼
  -mapper: Spatie\LaravelSettings\SettingsMapper {#2351 ▶}
  -config: Spatie\LaravelSettings\SettingsConfig {[#4669 ▶](https://helixsleep.test/#sf-dump-1046035305-ref24669)}
  -loaded: true
  -configInitialized: true
  #originalValues: Illuminate\Support\Collection {#4453 ▶}
  +payload: {[#4617 ▶](https://helixsleep.test/#sf-dump-1046035305-ref24617)}
  payload: {[#4617 ▼](https://helixsleep.test/#sf-dump-1046035305-ref24617) // <-- Now a stdClass
        +"type": "zaius"
        +"button": "<div><strong>VIEW OFFER*</strong></div>"
        +"text_color": "#ffffff"
        +"padding_top": "12"
        +"content_mobile": "<div>25% Off Sitewide + FREE Bundle! Ends 12/3</div>"
        +"padding_bottom": "12"
        +"content_desktop": "<div>🎁 Cyber Monday Sale! 25% OFF SITEWIDE + FREE Bundle With All Mattress Purchases ($330+ Value)! Offer Ends 12/3✨</div>"
        +"background_color": "#af295c"
        +"zaius_content_id": "2021__fourth_of_july__top_bar_pop_up_2021_-_fourth_of_july_-_top_bar_pop_up_2021_-_fourth_of_july_-_top_bar_pop_up_web_modal"
        +"center_align_content": true
        +"countdown_timer_enabled": false
      }
  enabled: true
}

Would it be possible to revert this change or make it an opt-in instead?

Thank you.

Reverted with 3.2.3, maybe we'll add this in v4, we'll see when we get there