ronasit / laravel-entity-generator
Provided console command for generating entities.
Installs: 49 199
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 5
Forks: 4
Open Issues: 7
pkg:composer/ronasit/laravel-entity-generator
Requires
- php: ^8.3
- ext-json: *
- doctrine/dbal: ^4.2
- laravel/framework: >=11.31.0
- laravel/legacy-factories: >=1.4.0
- ronasit/laravel-helpers: >=3.4
Requires (Dev)
- fakerphp/faker: ^1.24.0
- mikey179/vfsstream: ^1.6.12
- mockery/mockery: ^1.6.12
- orchestra/testbench: ^9.5.2
- php-coveralls/php-coveralls: ^2.7
- php-mock/php-mock: ^2.5
- phpunit/phpunit: ^10.5.38
- dev-master
- 3.4.1
- 3.4
- 3.3.10
- 3.3.9
- 3.3.8
- 3.3.7
- 3.3.6
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2
- 3.1
- 3.0.0-beta
- 2.0.4-beta
- 2.0.3-beta
- 2.0.2-beta
- 2.0.1-beta
- 2.0.0-beta
- 1.3.12
- 1.3.11
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.1.0-beta
- dev-140-use-NovaResource-class-in-NovaTestGenerator-instead-of-Model
- dev-179-resource-exists-exception
- dev-159-ability-to-set-nova-resource-for-nova-tests-generator
- dev-EXAMPLE-140-use-NovaResource-class-in-NovaTestGenerator-instead-of-Model
This package is auto-updated.
Last update: 2025-10-06 10:40:21 UTC
README
Laravel-Entity-Generator - This generator is used to create a standard class stack for a new entity.
Installation
Install package using dev
mode
composer require ronasit/laravel-entity-generator --dev
Publish package's resources.
php artisan vendor:publish --provider="RonasIT\Support\EntityGeneratorServiceProvider"
Usage
Entity generation
Call make:entity
artisan command to run the generation command for the full stack of the entity classes:
php artisan make:entity Post
Entity name may contain the subfolder, in this case generated model
and nova resource
will be placed to
the subfolder as well:
php artisan make:entity Forum/Blog/Post
Fields definition options
The make:entity
provides an ability to set the entity's fields, which will be used in all created classes (e.g. Model, Create/Update requests, Test fixtures, etc.)
php artisan make:entity Post -S title -S text -t published_at
The following field types are available to use:
Type | Modificator | Short Option | Full Option |
---|---|---|---|
integer |
-i |
--integer |
|
integer |
required | -I |
--integer-required |
float |
-f |
--float |
|
float |
required | -F |
--float-required |
string |
-s |
--string |
|
string |
required | -S |
--string-required |
boolean |
-b |
--boolean |
|
boolean |
required | -B |
--boolean-required |
datetime |
-t |
--timestamp |
|
datetime |
required | -T |
--timestamp-required |
json |
-j |
--json |
Relations definitions options
Command also provides an ability to set relations, which will be added to the model
php artisan make:entity Post -A Comment -A Reaction
Relation may be placed in the subfolder, in this case - set the relative namespace from the model directory:
php artisan make:entity Post -A Blog/Comment -A Forum/Common/Reaction
The following options are available to set relations:
Type | Short Option | Full Option |
---|---|---|
Has one | -a |
--has-one |
Has many | -A |
--has-many |
Belongs to | -e |
--belongs-to |
Belongs to many | -E |
--belongs-to-many |
Single class generation mode options
Command allows to generate only single entity-related class
php artisan make:entity Post --only-tests
The following options are available:
--only-model
--only-repository
--only-service
--only-controller
--only-requests
--only-migration
--only-factory
--only-tests
--only-seeder
--only-resource
Mode combination options
Sometimes you need to generate the stack of classes to work with some entity only inside the application without the ability to manipulate it using API, or you need to create only API for already existed entity.
For this task, there are two mutually exclusive options:
--only-entity
, generate stack of classes to work with entity only inside the app, it includes:
migration
model
service
repository
--only-api
, generate stack of classes to implement API part to work with already existed entity:
routes
controller
requests
tests
Methods setting options
By default, the command generate all methods from the CRUD stack which includes:
- create
- update
- delete
- search
- get by id
But what if we need to create the interface only for updating and reading the entity? Just use the methods
option for it:
php artisan make:entity Post --methods=RU
Feel free to use any combinations of actions in any order. Each action has its own character:
C
createU
updateD
deleteR
read (search and get by id)
Release notes
1.3
Since 1.3 version you need to add to your config/entity-generator.php following data:
'paths' => [ ... // your old data 'seeds' => 'database/seeds', 'database_seeder' => 'database/seeds/DatabaseSeeder.php', 'translations' => 'lang/en/validation.php' ], 'stubs' => [ ... // your old data 'empty_factory' => 'entity-generator::empty_factory', 'translation_not_found' => 'entity-generator::translation_not_found', 'validation' => 'entity-generator::validation', 'seeder' => 'entity-generator::seeder', 'database_empty_seeder' => 'entity-generator::database_empty_seeder' ]