Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Helpers: Arr and Data

Work with arrays efficiently using Laravel helpers.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Arr Helper
  2. Arr Methods
  3. Data Helper
  4. Dot Notation

Array helpers:

Arr Helper

php
Arr::get($array, 'user.name', 'default');
Arr::set($array, 'user.name', 'John');
Arr::has($array, 'user.name');

Arr Methods

php
Arr::first($array, fn($v) => $v > 10);
Arr::last($array);
Arr::pluck($array, 'name');
Arr::only($array, ['id', 'name']);

Data Helper

php
$value = data_get($data, 'user.posts.*.title');
data_set($data, 'user.name', 'John');
data_fill($data, 'user.name', 'Default');

Dot Notation

php
$flat = Arr::dot($array);
$nested = Arr::undot($flat);
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read