Source: dev.to

Laravel data_get()
A função data_get() está presente na documentação do Laravel desde a versão 5.5 porém talvez você nunca a tenha usado. A função data_get() recupera o valor de um objeto ou matriz usando "dot" notation, e o melhor é que caso a chave passada não exista, não retornara erros de exceção, apenas null ou o valor default informado. exemplo: $data = ['products' => ['desk' => ['price' => 100]]]; $price = data_get($data, 'products.desk.price'); // 100 $price = data_get($data, 'products.desk.total_price'); // null Exit fullscreen mode exemplo utilizando request: $data = $request->all(); $price = data_get($data, 'products.desk.price'); // 100
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners