@@ -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
1833The 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
316331This method a shortcut for the validation rule.
317332
318333#### Usage
334+
319335```
320336public 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
332349when converting to json.
333350
334351E.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+
338360This 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
0 commit comments