This package aims to generate code on the target files in order to increase productivity. In this first release, relationsips are covered almost entirely.
bakgul/laravel-code-generator is a Laravel package for this package aims to generate code on the target files in order to increase productivity. in this first release, relationsips are covered almost entirely..
It currently has 2 GitHub stars and 67 downloads on Packagist (latest version v4.0.1).
Install it with composer require bakgul/laravel-code-generator.
Discover more Laravel packages by bakgul
or browse all Laravel packages to compare alternatives.
Last updated
This package aims to generate code on the target files in order to increase productivity. In this first release, relationsips are covered almost entirely.
It should be production-ready but hasn't been tested enough. You should use it carefully since this package will manipulate your files and folders. Always use a version-control, and make sure you have File History to be able to roll back the changes.
vendor/bakgul/kernel/config/apps.php file and see the changes. We have a new key named routes under each app. Bring that new structure to your packagify.php file in your config folder.'bundler' => 'vite' or 'mix' to the main array under 'Main from Kernel' section in your packagify.php file in your config folder.If you installed Packagified Laravel, you should have this package already. So skip installation.
sail composer require bakgul/laravel-code-generator
NOTE: Another package named Laravel File Creator will not be installed by this one. But this package will need it to create pivot models. If you work with pivot models, install Laravel File Creator afterwards.
This package can be used to add Eloquent relationship into the models and migrations. The implemented relations are:
In the future release, one of many will also be covered.
create:relation {relation} {from} {to} {mediator?} {--m|model} {--p|polymorphic}
relation: One of the shorthands of the type of the eloquent relationships:
from: This is the "has" part of the relationship. Argument's schema is package/table:column:model.
package: It's optional, and will be ignored when you create a "Standalone Laravel" or "Standalone Package".
table: It's required, and it should be the migration file's name's part between "create_" and "_table".
column: It's optional.
model: It's optional.
to: This is the "belongsTo" part of the relationship. Argument's schema is package/table:column:model.
package: It's optional, and will be ignored when you create a "Standalone Laravel" or "Standalone Package".
table: It's required, and it should be the migration file's name's part between "create_" and "_table".
column: It's optional.
mediator (as bridge): This is the middleman of the "Has One Through" and "Has Many Through" relationships. So the argument named "mediator" becomes a middleman when the relation is oto or otm. Argument's schema is package/table:column:model.
package: It's optional, and will be ignored when you create a "Standalone Laravel" or "Standalone Package".
table: It's required, and it should be the migration file's name's part between "create_" and "_table".
column: This is also optional, but it's internal schema is diffetent than the columns of the other arguments. What it's expected here is two column names that glued up with a dot (col_1.col_2). The first column is the foreign key that is connected to the has side, while the second one is the local key that related to the belongsTo side. That being said, you can specify only one column name. The other one will be "id" in this case. "email" is equal to "email.id" and ".email" is equal to "id.email" and no column means "id.id." Finally, if the second key ends with "_id," it will be used without prefixed with table name.
model: This is optional. It can be specified only when you want your migration and model names are irrelevant.
mediator (as pivot): When the relationship is "Many to Many" the mediator becomes the pivot. It's optional. When it doen't exist, Laravel conventions will be followed. In other words, if from is comments, and to is posts, then the migration will be comment_post. Argument's schema is package/table:model.
package: It's optional.
table: If you pass the mediator block, table name is required.
model: If you want to create a model for the pivot table, you can specify the model name here. If the model name can be produced from the table name like post_user and PostUser, it's enough to add -m to the command instead of specifiying the model name.
Model: While generating a many-to-many relationship, a model for pivot table will be created if " -m " or " --model " is added to the command.
Polymorphic: When the command has " -p " or " --polymorphic the relation will be converted to polymorhic of the specified relation type in its argument.
The main package that includes this one can be found here: Packagified Laravel