Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,25 @@ composer require laranail/enumerator

The service provider is auto-discovered. One trait — `use HasEnumerator;` — composes labels, comparisons, bitmasks, grouping, lifecycle, transitions, and factories.

## Quick start
## Quick start guide and usage

### Getting started

Nothing to configure: the service provider registers itself through package discovery, and an enum
needs only the trait. Optional steps, each for one feature:

```bash
# Scaffold an enum into App\Enums
php artisan laranail::enumerator.make UserStatusEnum

# The state-history table, only if you record transitions
php artisan vendor:publish --tag=laranail::enumerator-migrations
php artisan migrate
```

`ENUMERATOR_CSS` picks the Blade components' CSS framework (`plain` by default).

### Usage

```php
use Simtabi\Laranail\Enumerator\Concerns\HasEnumeratorBehavior;
Expand All @@ -38,6 +56,19 @@ UserStatusEnum::Active->is('active'); // true
UserStatusEnum::options(); // ['active' => 'Active', 'inactive' => 'Inactive', 'banned' => 'Banned']
```

```php
use Simtabi\Laranail\Enumerator\Casts\AsEnum;

protected function casts(): array
{
return ['status' => AsEnum::of(UserStatusEnum::class)]; // null-aware + name lookup
}
```

```blade
<x-laranail-enumerator::badge :case="$user->status" />
```

The full walkthrough is in [Getting started](docs/getting-started.md); everything else is in the [documentation index](#documentation).

## <a name="documentation"></a>Documentation
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
Publish the config file:

```bash
php artisan vendor:publish --tag=enumerator-config
php artisan vendor:publish --tag=laranail::enumerator-config
```

It writes to `config/enumerator.php`. Every key is documented inline.
It writes to `config/laranail/enumerator.php`. Every key is documented inline.

## Keys

Expand Down Expand Up @@ -54,7 +54,7 @@ keys fully replace the attribute value.
## Environment variable surface

Every env var the package reads. Defaults shown match
`config/enumerator.php`. Set in `.env` (or your environment's
`config/laranail/enumerator.php`. Set in `.env` (or your environment's
equivalent) to override; an empty/missing value falls back to the
default.

Expand All @@ -65,7 +65,7 @@ default.
| `ENUMERATOR_ALPINE_VERSION` | `alpine.version` | `3.15.12` | Alpine.js semver (used by `<x-...::alpine-loader />`) |
| `ENUMERATOR_ALPINE_INTEGRITY` | `alpine.integrity` | (pinned SHA-384) | SRI hash for the pinned bundle; empty disables SRI |
| `ENUMERATOR_ALPINE_CDN` | `alpine.cdn_url` | jsDelivr | URL pattern with `{version}` placeholder |
| `ENUMERATOR_ALPINE_LOCAL` | `alpine.local_url` | `/vendor/laranail-enumerator/alpine.min.js` | Local-fallback URL after `vendor:publish --tag=enumerator-js` |
| `ENUMERATOR_ALPINE_LOCAL` | `alpine.local_url` | `/vendor/laranail-enumerator/alpine.min.js` | Local-fallback URL after `vendor:publish --tag=laranail::enumerator-js` |
| `ENUMERATOR_TRANSLATOR` | `translator.adapter` | `null` | FQCN implementing `Contracts\TranslatorAdapter` |
| `ENUMERATOR_TENANCY_DRIVER` | `tenancy.driver` | `null` | FQCN implementing `Contracts\TenantContext` |
| `ENUMERATOR_MODULE_PEST` | `modules.pest` | `false` | `true` / `false` |
Expand Down
23 changes: 8 additions & 15 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,28 @@ Every asset bundle is independently publishable:

```bash
# Config
php artisan vendor:publish --tag=enumerator-config
php artisan vendor:publish --tag=laranail::enumerator-config

# Language strings
php artisan vendor:publish --tag=enumerator-lang
php artisan vendor:publish --tag=laranail::enumerator-lang

# All Blade view bundles
php artisan vendor:publish --tag=enumerator-views

# A single CSS-framework view bundle
php artisan vendor:publish --tag=enumerator-views-tailwind
php artisan vendor:publish --tag=enumerator-views-daisyui
php artisan vendor:publish --tag=enumerator-views-bootstrap
php artisan vendor:publish --tag=enumerator-views-bulma
php artisan vendor:publish --tag=enumerator-views-plain
# Blade views (every CSS-framework bundle; there is no per-framework tag)
php artisan vendor:publish --tag=laranail::enumerator-views

# laranail::enumerator.make stubs (for customization)
php artisan vendor:publish --tag=enumerator-stubs
php artisan vendor:publish --tag=laranail::enumerator-stubs

# State-history migration
php artisan vendor:publish --tag=enumerator-migrations
php artisan vendor:publish --tag=laranail::enumerator-migrations
php artisan migrate

# Preset enums copied into app/Enums/
php artisan vendor:publish --tag=enumerator-presets
php artisan vendor:publish --tag=laranail::enumerator-presets
```

## CSS framework

Set the default CSS framework for Blade components in `config/enumerator.php`:
Set the default CSS framework for Blade components in `config/laranail/enumerator.php`:

```php
'css_framework' => 'tailwind', // plain | tailwind | daisyui | bootstrap | bulma
Expand Down
4 changes: 2 additions & 2 deletions docs/recipes/customizing-presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Two paths:
**1. Override in config** (preferred, no code copy):

```php
// config/enumerator.php
// config/laranail/enumerator.php
'overrides' => [
Simtabi\Laranail\Enumerator\Presets\Enums\PriorityEnum::class => [
'Critical' => ['color' => 'magenta', 'meta' => ['paging' => true]],
Expand All @@ -16,7 +16,7 @@ Two paths:
**2. Copy and own** (when you need structural changes):

```bash
php artisan vendor:publish --tag=enumerator-presets
php artisan vendor:publish --tag=laranail::enumerator-presets
# Files copied into app/Enums/ — edit freely.
```

Expand Down
8 changes: 4 additions & 4 deletions docs/tools/alpine-loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ The component emits a tiny inline script that:
have run:

```bash
php artisan vendor:publish --tag=enumerator-js
php artisan vendor:publish --tag=laranail::enumerator-js
```

once. The bundle copies to `public/vendor/laranail-enumerator/alpine.min.js`.

## Configuration

`config/enumerator.php`:
`config/laranail/enumerator.php`:

```php
'alpine' => [
Expand Down Expand Up @@ -81,7 +81,7 @@ the CDN entirely:
```

The component loads directly from `local_url`. You still need to have
run `vendor:publish --tag=enumerator-js`.
run `vendor:publish --tag=laranail::enumerator-js`.

## Opt-out — you already ship Alpine

Expand All @@ -102,7 +102,7 @@ can't drift from the integrity hash without breaking the build.

When a new Alpine version is released:

1. Update `'version'` in `config/enumerator.php`.
1. Update `'version'` in `config/laranail/enumerator.php`.
2. Re-download the matching `cdn.min.js` to `resources/js/alpine.min.js`.
3. Recompute the SHA-384 SRI and update `'integrity'`.
4. CI passes → ship.
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/blade-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Five framework variants ship per component (where styling applies):
view bundle to customise:

```bash
php artisan vendor:publish --tag=enumerator-views
php artisan vendor:publish --tag=laranail::enumerator-views
```

`<x-laranail-enumerator::alpine-loader>` is framework-agnostic.
Expand Down
2 changes: 1 addition & 1 deletion docs/tools/make-enumerator.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ php artisan laranail::enumerator.make Color --stub=pure
Customize stubs:

```bash
php artisan vendor:publish --tag=enumerator-stubs
php artisan vendor:publish --tag=laranail::enumerator-stubs
# edit resources/stubs/enumerator/enumerator.*.stub
```

Expand Down
2 changes: 1 addition & 1 deletion docs/tools/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Twenty-seven native enum presets ship under `Simtabi\Laranail\Enumerator\Presets
Use directly via `use`, or copy into your app:

```bash
php artisan vendor:publish --tag=enumerator-presets
php artisan vendor:publish --tag=laranail::enumerator-presets
```

## `AlertTypeEnum` vs `SeverityEnum`
Expand Down
9 changes: 3 additions & 6 deletions docs/tools/views-publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
Each CSS-framework view bundle is independently publishable:

```bash
php artisan vendor:publish --tag=enumerator-views # all bundles
php artisan vendor:publish --tag=enumerator-views-plain
php artisan vendor:publish --tag=enumerator-views-tailwind
php artisan vendor:publish --tag=enumerator-views-daisyui
php artisan vendor:publish --tag=enumerator-views-bootstrap
php artisan vendor:publish --tag=enumerator-views-bulma
php artisan vendor:publish --tag=laranail::enumerator-views # every bundle
```

There is no per-framework tag: publishing writes all bundles, and you keep the one you use.

Published views land under `resources/views/vendor/laranail-enumerator/components/{framework}/` — edit freely; they override package defaults.

---
Expand Down
Loading