Collection of additional class creation commands for Artisan
This package expands on the basic artisan commands for creating classes.
To customize the generation of Laravel classes, read the Laravel Documentation.
Require this package with composer. It is recommended to only require the package for development.
composer require digitalion/laravel-makes
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
Once the package is installed, you'll have additional Artisan commands:
Create a new generic class in: App\Classes\
php artisan make:class DigitalionClass
Create a new enum class in: App\Enums\
php artisan make:enum DigitalionEnum
Enums implement the trait Digitalion\LaravelMakes\Traits\EnumSerializableTrait
that adds useful methods for using enums. View the enum methods
Create a new helper class in: App\Helpers\
php artisan make:helper DigitalionHelper
Create a new query scope class in: App\Interfaces\
php artisan make:interface DigitalionInterface
Create a new query scope class in: App\Scopes\
php artisan make:scope DigitalionScope
Create a new query scope class in: App\Services\
php artisan make:service DigitalionService
Create a new trait class in: App\Traits\
php artisan make:trait DigitalionTrait
$options = DigitalionEnum::options();
// dump $options
[
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
]
$values = DigitalionEnum::values();
// dump $values
[
'value1',
'value2',
'value3',
]
$keys = DigitalionEnum::keys();
// dump $keys
[
'key1',
'key2',
'key3',
]
This method returns a string with all the values of the enum, divided by the comma.
You may find this useful if you use it in Laravel's validation rules such as in:
.
$valuesString = DigitalionEnum::valuesImplode();
// dump $valuesString
'value1,value2,value3'
This method returns a string with regex to validate the Enum values. You may find this useful by using it in routes to accept only its values in parameters (Laravel Docs - Regular Expression Constraints).
$valuesRegex = DigitalionEnum::valuesRegex();
// dump $valuesRegex
'(value1|value2|value3)$'
By passing the translation key prefix of the enum values, you will get an array with all the translated keys and values.
File: resources/lang/en/enums.php
return [
'digitalion' => [
'key1' => 'Value 1',
'key2' => 'Value 2',
'key3' => 'Value 3',
],
];
Use:
$trans = DigitalionEnum::trans('enums.digitalion');
// dump $trans
[
'key1' => 'Value 1',
'key2' => 'Value 2',
'key3' => 'Value 3',
]
The MIT License (MIT). Please see License File for more information.