Skip to content

Commit 478c2d3

Browse files
committed
MOD stub formatting
Update README.md
1 parent 1f26573 commit 478c2d3

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

README.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ composer require webfox/laravel-backed-enums
1313

1414
## Usage
1515

16+
### Make Command
17+
18+
You can use the `make:laravel-backed-enum` command to create a new enum.
19+
20+
```bash
21+
php artisan make:laravel-backed-enum {name} {enumType}
22+
```
23+
24+
This will create a new enum in the `app/Enums` directory.
25+
26+
The command takes in two arguments:
27+
28+
- name: The name of the enum
29+
- enumType: The type of the enum. This can be either `string` or `int`. Default is `string`.
30+
1631
### Setup your enum
1732

1833
The enum you create must implement the `BackedEnum` interface and also use the `IsBackedEnum` trait.
@@ -316,6 +331,7 @@ The backed enums may be validated using Laravel's standard Enum validation rule
316331
This method a shortcut for the validation rule.
317332

318333
#### Usage
334+
319335
```
320336
public function rules(): array
321337
{
@@ -328,34 +344,41 @@ public function rules(): array
328344
## Other Classes
329345

330346
### AsFullEnumCollection
331-
This cast is similar to the Laravel built in `AsEnumCollection` cast but unlike the built-in will maintain the full `toArray` structure
347+
348+
This cast is similar to the Laravel built in `AsEnumCollection` cast but unlike the built-in will maintain the full `toArray` structure
332349
when converting to json.
333350

334351
E.g. the Laravel built in `AsEnumCollection` cast will return the following json:
352+
335353
```json
336-
["MILLIGRAMS", "GRAMS"]
354+
[
355+
"MILLIGRAMS",
356+
"GRAMS"
357+
]
337358
```
359+
338360
This cast will return
361+
339362
```json
340363
[
341-
{
342-
"name": "MILLIGRAMS",
343-
"value": "MILLIGRAMS",
344-
"label": "mg",
345-
"meta": {
346-
"background_color": "bg-green-100",
347-
"text_color": "text-green-800"
348-
}
349-
},
350-
{
351-
"name": "GRAMS",
352-
"value": "GRAMS",
353-
"label": "g",
354-
"meta": {
355-
"background_color": "bg-red-100",
356-
"text_color": "text-red-800"
364+
{
365+
"name": "MILLIGRAMS",
366+
"value": "MILLIGRAMS",
367+
"label": "mg",
368+
"meta": {
369+
"background_color": "bg-green-100",
370+
"text_color": "text-green-800"
371+
}
372+
},
373+
{
374+
"name": "GRAMS",
375+
"value": "GRAMS",
376+
"label": "g",
377+
"meta": {
378+
"background_color": "bg-red-100",
379+
"text_color": "text-red-800"
380+
}
357381
}
358-
}
359382
]
360383
```
361384

src/stubs/laravel-backed-enum.stub

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ namespace {{ namespace }};
55
use Webfox\LaravelBackedEnums\BackedEnum;
66
use Webfox\LaravelBackedEnums\IsBackedEnum;
77

8-
enum {{ name }}:{{ enumType }} implements BackedEnum
8+
enum {{ name }}: {{ enumType }} implements BackedEnum
99
{
1010
use IsBackedEnum;
1111

1212
/**
13-
* Add your Enums below using.
14-
* e.g. case Standard = 'standard';
15-
*/
13+
* Add your Enums below using.
14+
* e.g. case Standard = 'standard';
15+
*/
1616

1717

1818
}

0 commit comments

Comments
 (0)