PHPackages                             lemaur/laravel-typed-arr - 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. lemaur/laravel-typed-arr

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

lemaur/laravel-typed-arr
========================

0.2.0(2y ago)05[2 PRs](https://github.com/leMaur/laravel-typed-arr/pulls)MITPHPPHP ^8.1

Since May 31Pushed 1y ago1 watchersCompare

[ Source](https://github.com/leMaur/laravel-typed-arr)[ Packagist](https://packagist.org/packages/lemaur/laravel-typed-arr)[ Docs](https://github.com/lemaur/laravel-typed-arr)[ RSS](/packages/lemaur-laravel-typed-arr/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (5)Used By (0)

Laravel Typed Arr
=================

[](#laravel-typed-arr)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4f3fdb9fa6764ae5a19c93d9ca09b51f89a3031be8a2d5aa11598964ff224ee5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c656d6175722f6c61726176656c2d74797065642d6172722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lemaur/laravel-typed-arr)[![Total Downloads](https://camo.githubusercontent.com/0ba131b4aa6b5f9f7ad310198f40b9e1fb5750322d98984edef788a3f5373be8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c656d6175722f6c61726176656c2d74797065642d6172722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lemaur/laravel-typed-arr)[![License](https://camo.githubusercontent.com/e81599f0a2e4e24dc838667fc62e75520993c67f826b39b251fec2e977316181/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c656d6175722f6c61726176656c2d74797065642d6172722e7376673f7374796c653d666c61742d73717561726526636f6c6f723d79656c6c6f77)](https://github.com/leMaur/laravel-typed-arr/blob/main/LICENSE.md)[![Tests](https://camo.githubusercontent.com/2283dc9aa398a89897da7debb4c40383e138ebdafdb060d2f165dbae0c35bf3a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c656d6175722f6c61726176656c2d74797065642d6172722f72756e2d74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/leMaur/laravel-typed-arr/actions/workflows/run-tests.yml)[![GitHub Sponsors](https://camo.githubusercontent.com/67130ea26c0cdbb7c18af5c1fd1c7995f000bc3da607abffed1e39d789f48b2f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f6c656d6175723f7374796c653d666c61742d73717561726526636f6c6f723d656134616161)](https://github.com/sponsors/leMaur)[![Trees](https://camo.githubusercontent.com/f12f2059f308501188008a8639ea876a9d8f8f3ce4047ea60b328985fc08b312/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f636f6c6f723d79656c6c6f77677265656e267374796c653d666c61742d737175617265266c6162656c3d54726565732671756572793d2532342e746f74616c2675726c3d68747470732533412532462532467075626c69632e6f66667365742e656172746825324675736572732532466c656d6175722532467472656573)](https://ecologi.com/lemaur?r=6012e849de97da001ddfd6c9)

This package provides an object-oriented way to retrieve the Array data with the right type.

If you are familiar with static analysis tool like phpstan, you've probably encountered `Cannot cast mixed to string` error (or similar).

This is usually happen when you try to cast a value returned from a method/function with a `mixed` return type.

With this package you can get a string value (and not only string) directly from the [Arr helper](https://laravel.com/docs/master/helpers#arrays) like:

```
use \Illuminate\Support\Arr;

/** @var \Illuminate\Support\Stringable $myValue */
$myValue = Arr::string($data, 'my-value');
```

Support Me
----------

[](#support-me)

Hey folks,

Do you like this package? Do you find it useful, and it fits well in your project?

I am glad to help you, and I would be so grateful if you considered supporting my work.

You can even choose 😃:

- You can [sponsor me 😎](https://github.com/sponsors/leMaur) with a monthly subscription.
- You can [buy me a coffee ☕ or a pizza 🍕](https://github.com/sponsors/leMaur?frequency=one-time&sponsor=leMaur) just for this package.
- You can [plant trees 🌴](https://ecologi.com/lemaur?r=6012e849de97da001ddfd6c9). By using this link we will both receive 30 trees for free and the planet (and me) will thank you.
- You can "Star ⭐" this repository (it's free 😉).

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

[](#installation)

You can install the package via composer:

```
composer require lemaur/laravel-typed-arr
```

Usage
-----

[](#usage)

### Retrieving Stringable from Arr helper

[](#retrieving-stringable-from-arr-helper)

You may use the `string` method to retrieve the Arr helper item as an instance of `Illuminate\Support\Stringable`:

```
use \Illuminate\Support\Arr;

/** @var \Illuminate\Support\Stringable $name */
$name = Arr::string($data, 'name');
```

### Retrieving Boolean from Arr helper

[](#retrieving-boolean-from-arr-helper)

You may use the `boolean` method to retrieve the Arr helper item as a boolean. The `boolean` method returns `true` for 1, "1", true, "true", "on", and "yes". All other values will return `false`:

```
use \Illuminate\Support\Arr;

/** @var bool $archived */
$archived = Arr::boolean($data, 'archived');
```

### Retrieving Integer from Arr helper

[](#retrieving-integer-from-arr-helper)

You may use the `integer` method to retrieve the Arr helper item as an integer:

```
use \Illuminate\Support\Arr;

/** @var int $count */
$count = Arr::integer($data, 'count');
```

### Retrieving Float from Arr helper

[](#retrieving-float-from-arr-helper)

You may use the `float` method to retrieve the Arr helper item as a float:

```
use \Illuminate\Support\Arr;

/** @var float $amount */
$amount = Arr::float($data, 'amount');
```

### Retrieving Date from Arr helper

[](#retrieving-date-from-arr-helper)

You may use the `date` method to retrieve the Arr helper item as a Carbon instance:

```
use \Illuminate\Support\Arr;

/** @var \Carbon\Carbon $birthday */
$birthday = Arr::date($data, 'birthday');
```

The second and third arguments accepted by the `date` method may be used to specify the date's format and timezone, respectively:

```
use \Illuminate\Support\Arr;

/** @var \Carbon\Carbon $elapsed */
$elapsed = Arr::date($data, 'elapsed', '!H:i', 'Europe/Madrid');
```

In case of an invalid format, an `InvalidArgumentException` will be thrown.

### Retrieving Enum from Arr helper

[](#retrieving-enum-from-arr-helper)

You may use the `enum` method to retrieve the Arr helper item as a [PHP enum](https://www.php.net/manual/en/language.types.enumerations.php) instance. In case of an invalid value or the enum does not have a backing value that matches the input value, `null` will be returned. The `enum` method accepts the name of the input value and the enum class as its first and second arguments:

```
use App\Enums\Status;
use \Illuminate\Support\Arr;

/** @var Status $status */
$status = Arr::enum($data, 'status', Status::class);
```

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)

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

License
-------

[](#license)

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

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~72 days

Total

2

Last Release

1005d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2696e190d36ed3a6809d954e3ae2153f969be340ef9b188f8a02bdc98b52f6c7?d=identicon)[leMaur](/maintainers/leMaur)

---

Top Contributors

[![leMaur](https://avatars.githubusercontent.com/u/2118799?v=4)](https://github.com/leMaur "leMaur (8 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (6 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

arraylaraveltypetyped-arraytypelaravelarrayarrlemaurTyped Arraylaravel-typed-arr

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lemaur-laravel-typed-arr/health.svg)

```
[![Health](https://phpackages.com/badges/lemaur-laravel-typed-arr/health.svg)](https://phpackages.com/packages/lemaur-laravel-typed-arr)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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