Skip to content

Commit

Permalink
Update README and CHANGELOG.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpoulter committed Jan 25, 2021
1 parent 9fb6a0f commit ec5fc8b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 13 deletions.
25 changes: 22 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@

All notable changes to `nova-enum-field` will be documented in this file.

## 2.3.0 - 2021-01-25

- Drop support for Laravel `7.x`
- Drop support for `laravel-enum < 3.1`.
- Add a customisable select filter.
- Add a customisable boolean filter.
- Add a flagged enum field.
- Refactor and simplify tests.

## 2.2.0 - 2020-09-25

- Add support for Laravel `8.x`.
- Add support for PHP `8.0`.
- Allow editing enums without casts.

## 2.1.0 - 2020-09-01

- Add support for `laravel-enum 2.2.0`.

## 2.0.0 - 2020-07-08

- Update `larave-enum` to `2.x`
- Drop support for laravel < `7.x`
- Add support for `laravel-enum 2.x`.
- Drop support for Laravel `< 7.x`.

## 1.1.0 - 2019-09-30

Expand All @@ -16,7 +35,7 @@ All notable changes to `nova-enum-field` will be documented in this file.
## 1.0.4 - 2019-09-27

- Add documentation.
- Refactor field code.
- Refactor `Enum` field code.

## 1.0.3 - 2019-09-27

Expand Down
57 changes: 47 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
[![MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Total Downloads](https://img.shields.io/packagist/dt/simplesquid/nova-enum-field.svg?style=flat-square)](https://packagist.org/packages/simplesquid/nova-enum-field)

Laravel Nova field to add enums to resources. This field uses
the [BenSampo/laravel-enum](https://github.com/BenSampo/laravel-enum) package, so make sure to check out the
installation instructions there first.
Laravel Nova field to add enums to resources. This field uses the [BenSampo/laravel-enum](https://github.com/BenSampo/laravel-enum) package, so make sure to check out the installation instructions there first.

![Screenshot of the enum field](https://github.com/simplesquid/nova-enum-field/raw/master/docs/screenshot.png)

Expand All @@ -21,8 +19,7 @@ composer require simplesquid/nova-enum-field

## Setup

This package requires that you use Attribute Casting in your models. From the docs
at [BenSampo/laravel-enum](https://github.com/BenSampo/laravel-enum#attribute-casting), this can be done like so:
It is strongly recommended that you use Attribute Casting in your models. From the docs at [BenSampo/laravel-enum](https://github.com/BenSampo/laravel-enum#attribute-casting), this can be done like this:

```php
use App\Enums\UserType;
Expand All @@ -41,7 +38,7 @@ class Example extends Model

## Usage

You can use the `Enum` field in your Nova resource like so:
You can use the `Enum` field in your Nova resource like this:

```php
namespace App\Nova;
Expand All @@ -66,13 +63,41 @@ class Example extends Resource
}
```

### Flagged Enums

You can use the `FlaggedEnum` field in your Nova resource like this (see [Flagged/Bitwise Enum](https://github.com/BenSampo/laravel-enum#flaggedbitwise-enum) setup):

```php
namespace App\Nova;

use App\Enums\UserPermissions;
use SimpleSquid\Nova\Fields\Enum\FlaggedEnum;

class Example extends Resource
{
// ...

public function fields(Request $request)
{
return [
// ...

FlaggedEnum::make('User Permissions')->attach(UserPermissions::class),

// ...
];
}
}
```

### Filters

If you would like to use the provided Nova Select filter, you can include it as such:
If you would like to use the provided Nova Select filter (which is compatible with both the `Enum` and `FlaggedEnum` fields), you can include it like this:

```php
namespace App\Nova;

use App\Enums\UserPermissions;
use App\Enums\UserType;
use SimpleSquid\Nova\Fields\Enum\EnumFilter;

Expand All @@ -85,18 +110,22 @@ class Example extends Resource
return [
new EnumFilter('user_type', UserType::class),

new EnumFilter('user_permissions', UserPermissions::class),

// Or with optional filter name:
// new EnumFilter('user_type', UserType::class, 'Type of user'),
(new EnumFilter('user_type', UserType::class))
->name('Type of user'),
];
}
}
```

Alternatively, you may wish to use the provided Nova Boolean filter:
Alternatively, you may wish to use the provided Nova Boolean filter (which is also compatible with both the `Enum` and `FlaggedEnum` fields):

```php
namespace App\Nova;

use App\Enums\UserPermissions;
use App\Enums\UserType;
use SimpleSquid\Nova\Fields\Enum\EnumBooleanFilter;

Expand All @@ -109,8 +138,16 @@ class Example extends Resource
return [
new EnumBooleanFilter('user_type', UserType::class),

new EnumBooleanFilter('user_permissions', UserPermissions::class),

// Or with optional filter name:
// new EnumBooleanFilter('user_type', UserType::class, 'Type of user'),
(new EnumBooleanFilter('user_type', UserType::class))
->name('Type of user'),

// When filtering a FlaggedEnum, it will default to filtering
// by ANY flags, however you may wish to filter by ALL flags:
(new EnumBooleanFilter('user_permissions', UserPermissions::class))
->filterAllFlags(),
];
}
}
Expand Down

0 comments on commit ec5fc8b

Please sign in to comment.