A Laravel package that provides an intelligent way to generate database-related components using OpenAI.
It extends the default artisan make commands in Laravel to automatically generate the content of each component using AI, based on the provided description.
The following commands are implemented in this package:
ai:rule- Generate custom validation rules using AIai:migration- Generate migration files using AIai:factory- Generate factory files using AIai:model- Generate model files using AI
Stay tuned for future updates as we continue to expand the capabilities of the Laravel Intelli DB package.
-
Install the package via composer:
composer require salehhashemi/laravel-intelli-db -
Publish the configuration file:
php artisan vendor:publish --provider="Salehhashemi\LaravelIntelliDb\LaravelIntelliDbServiceProvider" -
Add your OpenAI API key to the
.envfile:OPEN_AI_KEY=your_openai_key -
Optionally, you can change the default model used by OpenAI in the
.envfile:OPEN_AI_MODEL=gpt-4
To adjust the behavior of the AI text generation, you can set the following parameters in your configuration file:
'temperature' => 0.7
'frequency_penalty' => 0.2
To create a new validation rule using AI, run the following command:
php artisan ai:rule YourRuleName
You can provide the description of the rule using the --description option:
php artisan ai:rule YourRuleName --description="Your rule description"
If you don't provide a description, it will ask for it interactively.
The generated rule class will be placed in the app/Rules directory.
To create a new migration file using AI, run the following command:
php artisan ai:migration your_migration_name
You can provide the description of the migration using the --description option:
php artisan ai:migration your_migration_name --description="Your migration description"
You can also specify the table name for the migration with the --table option:
php artisan ai:migration your_migration_name --table=your_table_name
This will append the schema of the desired table to provide a better result.
And you can set the location where the migration file should be created using the --path option:
php artisan ai:migration your_migration_name --path=path/to/migrations
If you don't provide a description, it will ask for it interactively.
The generated migration file will be placed in the database/migrations directory or the specified path.
To create a new factory file using AI, run the following command:
php artisan ai:factory YourFactoryName
You can provide the name of the model for which the factory will be created using the --model option:
php artisan ai:factory YourFactoryName --model="YourModelName"
If you don't provide the model, it will ask for it interactively.
The generated factory file will be placed in the database/factories directory.
To create a new model file using AI, run the following command:
php artisan ai:model YourModelName
The generated model file will be placed in the app/Models directory.
The generated model will include PHP DocBlock comments for properties, relationships, and methods with appropriate type hints.
To create a rule that validates a unique email address, run:
php artisan ai:rule UniqueEmail --description="Validate unique email address"
To create a migration that adds an email column to the users table, run:
php artisan ai:migration AddEmailToUsersTable --description="Add email column to users table" --table=users
To create a factory for the User model, run:
php artisan ai:factory UserFactory --model="User"
To create a model named Address, run:
php artisan ai:model Address
composer testPlease see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.
