Sunday, April 9, 2017

how to turn array key into property so I can access it as property

I have an array of settings and I would like to access it like

$settings->type

instead of

$settings['type']

inside of blade. I prefer the first version since its more elegant.

here is my array:

array:5 [▼
  "enable" => "true"
  "type" => "native"
  "must_be_registered" => "true"
  "allow_nested" => "true"
  "nested_level" => "5"
]

I tried turning it into collection

Collection {#382 ▼
  #items: array:5 [▼
    "enable" => "true"
    "type" => "native"
    "must_be_registered" => "true"
    "allow_nested" => "true"
    "nested_level" => "5"
  ]
}

but that did not help really, I still could not do $settings->type inside blade, anyone knows how I can do this?

Property [type] does not exist on this collection instance.



via maxit

Advertisement