PHPackages                             codewiser/laravel-enum-casting - 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. codewiser/laravel-enum-casting

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

codewiser/laravel-enum-casting
==============================

Casts set or array of enums

1.0.0(4y ago)015MITPHPPHP ^8.1

Since Jun 2Pushed 4y ago2 watchersCompare

[ Source](https://github.com/C0deWiser/larvel-enum-casting)[ Packagist](https://packagist.org/packages/codewiser/laravel-enum-casting)[ RSS](/packages/codewiser-laravel-enum-casting/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (7)Used By (0)

Laravel Enum Casting
====================

[](#laravel-enum-casting)

[![PHP Composer](https://github.com/C0deWiser/larvel-enum-casting/actions/workflows/php.yml/badge.svg)](https://github.com/C0deWiser/larvel-enum-casting/actions/workflows/php.yml)

This package brings enums casting into Laravel projects.

Install
-------

[](#install)

```
composer require codewiser/laravel-enum-casting

```

Database
--------

[](#database)

We suppose that enums stored in database either as `set` or as `json` object.

### Set

[](#set)

```
superuser,adminstrator

```

To cast enums from `set` datatype, use `set` keyword.

### JSON

[](#json)

```
["superuser","adminstrator"]

```

To cast enums from `json` datatype, use `json` or `array` keyword.

Usage
-----

[](#usage)

> See also [Laravel documentation](https://laravel.com/docs/9.x/eloquent-mutators#array-and-json-casting)

### AsArray

[](#asarray)

Use `AsArray` to cast enums as a simple `array`. Provide datatype and Enum class as arguments:

```
use \Codewiser\Enum\Castable\AsArray;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'roles' => AsArray::class . ':set,' . MyEnum::class,
];
```

### AsArrayObject

[](#asarrayobject)

Use `AsArrayObject` to cast enums as `ArrayObject`. Provide datatype and Enum class as arguments:

```
use \Codewiser\Enum\Castable\AsArrayObject;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'roles' => AsArrayObject::class . ':json,' . MyEnum::class,
];
```

### AsCollection

[](#ascollection)

Use `AsCollection` to cast enums as `Collection`. Provide datatype and Enum class as arguments. Optionally you may pass custom collection class name:

```
use \Codewiser\Enum\Castable\AsCollection;

/**
 * The attributes that should be cast.
 *
 * @var array
 */
protected $casts = [
    'roles' => AsCollection::class . ':array,' . MyEnum::class . ',' . MyCollection::class,
];
```

> Arguments order has no matter.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 61.5% 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

Every ~0 days

Total

6

Last Release

1489d ago

Major Versions

0.1.2 → 1.0.02022-06-06

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1220316?v=4)[Michael Michaelson](/maintainers/Cellard)[@Cellard](https://github.com/Cellard)

![](https://www.gravatar.com/avatar/c61806bbffc006a40dedb9cf8f9d5ece666505cc57acc69d7f59d28024ae88bb?d=identicon)[abduraim](/maintainers/abduraim)

---

Top Contributors

[![abduraim](https://avatars.githubusercontent.com/u/17427874?v=4)](https://github.com/abduraim "abduraim (8 commits)")[![Cellard](https://avatars.githubusercontent.com/u/1220316?v=4)](https://github.com/Cellard "Cellard (5 commits)")

---

Tags

laravelarrayenum

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/codewiser-laravel-enum-casting/health.svg)

```
[![Health](https://phpackages.com/badges/codewiser-laravel-enum-casting/health.svg)](https://phpackages.com/packages/codewiser-laravel-enum-casting)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.9k69.5k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

8045.8k](/packages/firefly-iii-data-importer)[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2519.3k](/packages/iteks-laravel-enum)[ronasit/laravel-helpers

Provided helpers function and some helper class.

2085.6k31](/packages/ronasit-laravel-helpers)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)

PHPackages © 2026

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