Skip to content

Commit 0bab362

Browse files
committed
Update changelog and readme
1 parent 3568242 commit 0bab362

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
All notable changes to `laravel-enum` will be documented in this file:
44

5-
## 1.0.0 - 2021-03-05
5+
## 1.0.0 - 2021-03-08
66

77
- initial release

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,66 @@
44
![Tests](https://github.com/desmart/laravel-enum/workflows/Run%20Tests/badge.svg)
55
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://github.com/DeSmart/laravel-enum/blob/master/LICENSE)
66

7-
Package provides a simple trait that allows to use/generate UUIDs as IDs in Laravel models.
7+
Package provides a simple way to use strongly typed enum objects with Laravel models. It utilizes Laravel's custom
8+
casting mechanism.
89

910
## Installation
1011
To install the package via Composer, simply run the following command:
11-
```
12-
composer require desmart/laravel-uuid-id
12+
13+
```bash
14+
composer require desmart/laravel-enum
1315
```
1416

1517
## Usage
1618

19+
Create an enum class that extends `DeSmart\Laravel\Enumeration`. Then, simply define all possible values in form of
20+
class constants:
21+
22+
```php
23+
class Character extends DeSmart\Laravel\Enumeration
24+
{
25+
const GOOD = 'good';
26+
const EVIL = 'evil';
27+
const SOMETIMES_GOOD_SOMETIMES_EVIL = 'sometimes_good_sometimes_evil';
28+
}
29+
```
30+
31+
In Laravel model:
32+
33+
```php
34+
class Hero extends Model
35+
{
36+
/**
37+
* @var array
38+
*/
39+
protected $casts = [
40+
'character' => Character::class,
41+
];
42+
}
43+
```
44+
45+
That's it.
46+
47+
```php
48+
$hero = new Hero(['character' => Character::EVIL]);
49+
50+
dump($hero);
51+
// Hero {#293
52+
// ...
53+
// #casts: array:1 [
54+
// "character" => "Character"
55+
// ]
56+
// ...
57+
// #attributes: array:1 [
58+
// "character" => "evil"
59+
// ]
60+
// }
61+
62+
dump($hero->character);
63+
// Character {#296
64+
// -value: "good"
65+
// }
66+
```
1767
## Changelog
1868

1969
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

0 commit comments

Comments
 (0)