PHPackages                             abather/custom-data-helpers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. abather/custom-data-helpers

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

abather/custom-data-helpers
===========================

extend data helpers to include custom seperators.

v1.0.0(5mo ago)11MITPHPPHP ^8.2CI failing

Since Jan 13Pushed 5mo agoCompare

[ Source](https://github.com/Abather/custom-data-helpers)[ Packagist](https://packagist.org/packages/abather/custom-data-helpers)[ Docs](https://github.com/abather/custom-data-helpers)[ GitHub Sponsors](https://github.com/Abather)[ RSS](/packages/abather-custom-data-helpers/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

Custom Data Helpers for Laravel
===============================

[](#custom-data-helpers-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e0dbd4ac721418b19fbc9aae4bfa6786efb5f2b9afc99a8c948aeb4798508e80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616261746865722f637573746f6d2d646174612d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/abather/custom-data-helpers)[![GitHub Tests Action Status](https://camo.githubusercontent.com/da9354bc722fb3477f27433b06406b6eb8d1084b52bef1e7566c5a4d8593658d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616261746865722f637573746f6d2d646174612d68656c706572732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/abather/custom-data-helpers/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e73266be38b1760671aeb6a263fd4864e32936ba0bfc0647728fc54e203d608d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616261746865722f637573746f6d2d646174612d68656c706572732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/abather/custom-data-helpers/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0dee5fa258ef6f13d922a945ef6e2afe220578f4e7d868cbaff5054d858ebbea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616261746865722f637573746f6d2d646174612d68656c706572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/abather/custom-data-helpers)

Description
-----------

[](#description)

This Laravel package extends the default data helper functions (`data_get`, `data_set`, `data_forget`, `data_has`) to support **custom separators** instead of the hardcoded dot (`.`) notation.

Laravel's built-in data helpers are fantastic, but they use a fixed dot separator which can cause issues when your data keys contain actual dots. This package solves that problem by allowing you to specify any separator you want.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require abather/custom-data-helpers
```

That's it! The package will auto-register itself in Laravel and the helper functions will be available globally.

Usage
-----

[](#usage)

The package provides **three ways** to use custom data helpers:

### 1. Using the DataHelper Class (Recommended)

[](#1-using-the-datahelper-class-recommended)

```
use Abather\CustomDataHelpers\DataHelper;

$data = ['users' => ['profile' => ['name' => 'John']]];

// Get value with custom separator
DataHelper::get($data, 'users/profile/name', '/'); // 'John'

// Get with default value
DataHelper::get($data, 'users/profile/age', '/', 25); // 25 (if key doesn't exist)

// Set value
DataHelper::set($data, 'users/profile/email', 'john@example.com', true, '/');

// Check existence
DataHelper::has($data, 'users/profile/name', '/'); // true

// Remove key
DataHelper::forget($data, 'users/profile/email', '/');
```

### 2. Using Global Helper Functions

[](#2-using-global-helper-functions)

```
// All DataHelper methods are also available as global helper functions with _ prefix
_data_get($data, 'users/profile/name', '/'); // 'John'
_data_set($data, 'users/profile/email', 'john@example.com', true, '/');
_data_has($data, 'users/profile/name', '/'); // true
_data_forget($data, 'users/profile/email', '/');
```

---

### `DataHelper::get()` - Retrieve Values

[](#datahelperget---retrieve-values)

Retrieve a value from a nested array or object using a custom separator.

```
use Abather\CustomDataHelpers\DataHelper;

// Basic usage with default dot separator (backward compatible)
$data = ['products' => ['desk' => ['price' => 100]]];
DataHelper::get($data, 'products.desk.price'); // 100

// Using custom separator
$data = ['products' => ['desk' => ['price' => 100]]];
DataHelper::get($data, 'products/desk/price', '/'); // 100

// With default value
DataHelper::get($data, 'products/desk/discount', '/', 0); // 0

// Using wildcards to get multiple values
$data = [
    'products' => [
        ['name' => 'Desk', 'price' => 100],
        ['name' => 'Chair', 'price' => 50]
    ]
];
DataHelper::get($data, 'products/*/price', '/'); // [100, 50]

// Using placeholders
$flight = [
    'segments' => [
        ['from' => 'LHR', 'to' => 'IST'],
        ['from' => 'IST', 'to' => 'PKX'],
    ]
];
DataHelper::get($flight, 'segments->{first}->from', '->'); // 'LHR'
DataHelper::get($flight, 'segments->{last}->to', '->'); // 'PKX'

// Using different separators for different data structures
$config = ['app' => ['database' => ['host' => 'localhost']]];
DataHelper::get($config, 'app|database|host', '|'); // 'localhost'
DataHelper::get($config, 'app->database->host', '->'); // 'localhost'
DataHelper::get($config, 'app/database/host', '/'); // 'localhost'
```

### `DataHelper::set()` - Set Values

[](#datahelperset---set-values)

Set a value within a nested array or object using a custom separator.

```
use Abather\CustomDataHelpers\DataHelper;

$data = [];

// Basic usage
DataHelper::set($data, 'products|desk|price', 200, true, '|');
// Result: ['products' => ['desk' => ['price' => 200]]]

// Using wildcards for bulk updates
$products = [
    ['name' => 'Desk', 'price' => 100],
    ['name' => 'Chair', 'price' => 50]
];
DataHelper::set($products, '*/price', 0, true, '/');
// Sets all product prices to 0

// Conditional setting (don't overwrite existing values)
$data = ['products' => ['desk' => ['price' => 100]]];
DataHelper::set($data, 'products.desk.price', 200, false);
// Price remains 100

// Overwrite existing values (default behavior)
DataHelper::set($data, 'products.desk.price', 200, true);
// Price is now 200

// Create nested structures automatically
$data = [];
DataHelper::set($data, 'api/v1/endpoints/users', '/api/v1/users', true, '/');
// Result: ['api' => ['v1' => ['endpoints' => ['users' => '/api/v1/users']]]]

// Using object notation separator
$settings = [];
DataHelper::set($settings, 'app->theme->colors->primary', '#007bff', true, '->');
// Result: ['app' => ['theme' => ['colors' => ['primary' => '#007bff']]]]
```

### `DataHelper::has()` - Check if Key Exists

[](#datahelperhas---check-if-key-exists)

Check if a key exists in an array or object using a custom separator.

```
use Abather\CustomDataHelpers\DataHelper;

$data = ['products' => ['desk' => ['price' => 100]]];

// Basic usage
DataHelper::has($data, 'products.desk.price'); // true
DataHelper::has($data, 'products.desk.discount'); // false

// Using custom separator
DataHelper::has($data, 'products->desk->price', '->'); // true
DataHelper::has($data, 'products/desk/price', '/'); // true
DataHelper::has($data, 'products|desk|stock', '|'); // false

// Works with nested objects
$object = (object) [
    'user' => (object) [
        'profile' => (object) ['name' => 'John']
    ]
];
DataHelper::has($object, 'user/profile/name', '/'); // true
DataHelper::has($object, 'user/profile/email', '/'); // false

// Using with different separators
$routes = [
    'api' => [
        'v1' => ['users' => 'UsersController']
    ]
];
DataHelper::has($routes, 'api/v1/users', '/'); // true
DataHelper::has($routes, 'api->v1->users', '->'); // true
DataHelper::has($routes, 'api.v1.posts', '.'); // false
```

### `DataHelper::forget()` - Remove Values

[](#datahelperforget---remove-values)

Remove a value from a nested array or object using a custom separator.

```
use Abather\CustomDataHelpers\DataHelper;

$data = ['products' => ['desk' => ['price' => 100, 'stock' => 50]]];

// Basic usage
DataHelper::forget($data, 'products.desk.price');
// Result: ['products' => ['desk' => ['stock' => 50]]]

// Using custom separator
DataHelper::forget($data, 'products|desk|stock', '|');
// Result: ['products' => ['desk' => []]]

// Using wildcards to remove from multiple items
$products = [
    ['name' => 'Desk', 'price' => 100, 'discount' => 10],
    ['name' => 'Chair', 'price' => 50, 'discount' => 5]
];
DataHelper::forget($products, '*/discount', '/');
// Removes 'discount' from all products

// Using different separators
$config = [
    'app' => [
        'debug' => true,
        'cache' => ['enabled' => true, 'ttl' => 3600]
    ]
];
DataHelper::forget($config, 'app/cache/ttl', '/');
// Result: ['app' => ['debug' => true, 'cache' => ['enabled' => true]]]

DataHelper::forget($config, 'app->cache->enabled', '->');
// Result: ['app' => ['debug' => true, 'cache' => []]]
```

Real-World Use Cases
--------------------

[](#real-world-use-cases)

### 1. Working with Keys Containing Dots

[](#1-working-with-keys-containing-dots)

```
// API response with dotted keys
$config = [
    'app.name' => 'My Application',
    'app.env' => 'production',
    'database.host' => 'localhost'
];

// Access them safely using a different separator
$appName = _data_get($config, 'app.name', '|'); // 'My Application'
```

### 2. URL-Style Paths

[](#2-url-style-paths)

```
$routes = [
    'api' => [
        'v1' => [
            'users' => 'UsersController@index'
        ]
    ]
];

$controller = _data_get($routes, 'api/v1/users', '/');
// 'UsersController@index'
```

### 3. Object Notation Style

[](#3-object-notation-style)

```
$data = [
    'user' => [
        'profile' => [
            'settings' => [
                'theme' => 'dark'
            ]
        ]
    ]
];

$theme = _data_get($data, 'user->profile->settings->theme', '->');
// 'dark'
```

Backward Compatibility
----------------------

[](#backward-compatibility)

The DataHelper class and helper functions use dot notation by default, making them compatible with Laravel's conventions. The package uses underscore-prefixed global functions (`_data_*`) to avoid conflicts with Laravel's built-in helpers.

```
// Using default dot separator (no conflicts with Laravel)
DataHelper::get($array, 'user.name');
DataHelper::set($array, 'user.email', 'john@example.com');
DataHelper::has($array, 'user.profile');
DataHelper::forget($array, 'user.settings');

// Or using global helpers
_data_get($array, 'user.name');
_data_set($array, 'user.email', 'john@example.com');
_data_has($array, 'user.profile');
_data_forget($array, 'user.settings');
```

Features
--------

[](#features)

- ✅ Custom separator support for all data helpers
- ✅ Wildcard operations (`*`)
- ✅ Placeholder support (`{first}`, `{last}`)
- ✅ Works with arrays and objects
- ✅ Laravel Collections support
- ✅ 100% backward compatible with Laravel's default helpers
- ✅ No configuration needed
- ✅ Auto-discovery enabled
- ✅ Fully tested

Requirements
------------

[](#requirements)

- PHP 8.4 or higher
- Laravel 11.x or 12.x

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Abather](https://github.com/Abather)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance70

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

170d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d032b178010eeffd089ecd6f75934079dc36d2d41328827f1d19c729572cbeb?d=identicon)[Abather](/maintainers/Abather)

---

Top Contributors

[![Abather](https://avatars.githubusercontent.com/u/18185658?v=4)](https://github.com/Abather "Abather (6 commits)")

---

Tags

laraveldata-setAbathercustom-data-helpersdata\_get

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/abather-custom-data-helpers/health.svg)

```
[![Health](https://phpackages.com/badges/abather-custom-data-helpers/health.svg)](https://phpackages.com/packages/abather-custom-data-helpers)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
