amohamed/laravelmodelmaker

LaravelModelMaker is a powerful and easy-to-use package for Laravel developers...

v1.0.0 2023-05-06 17:14 UTC

This package is auto-updated.

Last update: 2024-10-09 13:16:42 UTC


README

Laravel Model Maker is a package that simplifies the process of generating models, migrations, and relationships in Laravel projects. It provides a set of artisan commands to create models with their corresponding migrations and relationships in a single command.

Features

  • Generate models with their corresponding migrations.
  • Create relationships (hasOne, hasMany, belongsTo, and belongsToMany) between models.
  • Easy to use artisan commands with a simple syntax.

Installation

To install the Laravel Model Maker package, use the following composer command:

composer require amohamed/laravelmodelmaker --dev

It is recommended to only require the package for development.

Usage

To generate a model and its migration, use the generate-model command:

php artisan atm:generate-model ModelName --fields="name:string:nullable,age:integer:unsigned:default(18),email:string:unique"

This command will create a model named ModelName in the app directory and its corresponding migration in the database/migrations directory. The migration will contain the name and age fields.

Generate Relationships

To generate relationships for an existing model, use the atm:generate-relationship command:

php artisan atm:generate-relationship

This command will prompt you to choose the desired relationships and related models for the specified model.

Example

Laravel Model Maker Example Laravel Model Maker Example

Available Options and Flags

$ php artisan atm:generate-model Post --fields="title:string,description:string:nullable,user_id:foreignId"

  Model name ................................................................................................................... Post  
  Fields ................................................................... title:string, description:string:nullable, user_id:foreignId  

Model and migration created successfully.

Would you like to generate relationships for this model? (yes/no) [no]:
> yes

Available relationship options:
1 => hasMany
2 => belongsTo
3 => hasOne
4 => belongsToMany

Select the relationships you want to generate for this model. You can specify multiple relationships by separating them with a comma.
> 1,2

Enter the related model for the 'hasMany' relationship:
> Comment

Enter the related model for the 'belongsTo' relationship:
> User

Relationships generated successfully.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to open an issue or create a pull request.

License

This package is released under the MIT License.