
Ingredients
data_get()
data_get() is a useful helper function in Laravel that retrieves values from a nested array or an object using dot notation.
The strength of data_get() is also that it accepts wildcards.
If you don't know or you don't use it, I suggest you to discover it (here the docs), with brothers and sisters:
data_set(),data_fill(),data_forget()! ;)
Arr::get()
Unlike data_get(), Arr::get() works only on arrays and it doesn't accept wildcards.
The Tip
Let’s show this example:
$array = [
'key.sub' => 'a-value'
];
data_get($array, 'key.sub'); // --> null ❗
// instead...
\Arr::get($array, 'key.sub'); // --> "a-value"
Instead of this:
$array = [
'key' => [
'sub' => 'a-value'
]
];
data_get($array, 'key.sub'); // --> "a-value"
// and also...
\Arr::get($array, 'key.sub'); // --> "a-value"
And you?
- Did you use already
data_get()? - And
Arr::get()? - Did you know that difference?
Leave your comment!
✸ Enjoy your coding!
If you liked this post, don't forget to Subscribe to my newsletter!
About the author
Senior Dev. Clean code lover and therefore lover of Laravel.
Best friend of deep work & focusing. Interested in critical thinking, self improvement, personal finance and rock'🤟'roll!
📍 I’m curious. I read a lot, listen, study, analyze. But I can’t stand fanaticism: I don’t like chasing after the last-minute framework all the time.
Comments
Join the discussionThe article 'data_get(): Warning with array keys with dots - Laravel Tips' is a crucial read for Laravel developers. It addresses a specific issue with data retrieval in arrays, providing practical solutions and best practices. This piece is particularly useful for those looking to avoid common pitfalls in Laravel development.https://crema-articulara.com/depanten-gel-cum-se-foloseste/



