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(3y ago)015MITPHPPHP ^8.1

Since Jun 2Pushed 3y ago3 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 1mo ago

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 49% 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

1440d ago

Major Versions

0.1.2 → 1.0.02022-06-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce23eaf7ae48d79d2b07efc83ff7cecb2664f428bd531b167b90169423f1453d?d=identicon)[Cellard](/maintainers/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

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[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.

2516.7k](/packages/iteks-laravel-enum)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[artisaninweb/laravel-enum

A provider for Enums in Laravel.

1187.5k](/packages/artisaninweb-laravel-enum)

PHPackages © 2026

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