Articles Snippets Projects

Retrieve Items from a deeply nested object or array

use Illuminate\Support\Arr;

// Retrieving an item from a nested object
 $user->team->subscription->name;
 object_get($user, 'team.subscription.name', 'default value');

// Retrieving an item from a nested array
 $data['user']['team']['subscription']['name'];
 Arr::get($data, 'user.team.subscription.name', 'default value');