Skip to content

Simplify database seeding with Laravel Factory Seeder Generator! Automatically create structured factories and seeders with intelligent data generation, customizable options, and seamless Laravel integration

Notifications You must be signed in to change notification settings

DaniloWA/laravel-factory-seeder-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest Version Total Downloads

Optimize Your Database Seeding with Laravel Factory Seeder Generator!

This package simplifies the creation of structured factories and seeders in Laravel applications, allowing developers to generate consistent and realistic test data with ease. It intelligently handles model attributes, including customizable data generation options and smart handling of casts. With features for logging, error handling, and extensive configuration options, this tool is essential for enhancing productivity and maintaining organized code in your development workflow.

📚 Index

🔍 Overview

The Laravel Factory Seeder Generator is an advanced tool designed to streamline the generation of factories and seeders within Laravel applications. This package automates the creation of seeding files, significantly enhancing productivity and reducing boilerplate code during the development process.

⭐ Features

  • Automatic Generation: Effortlessly create factories and seeders for all your models, eliminating repetitive tasks and allowing for faster development cycles.
  • Intelligent Data Filling: Automatically extracts all $fillable attributes from your models, ensuring that the correct fields are utilized for data generation.
  • Smart Handling of Casts: Utilizes defined casts in your model to produce realistic data with Laravel's Faker. If no casts are specified, it intelligently infers the most suitable cast for each $fillable field, optimizing data generation.
  • Seamless Integration: Integrates effortlessly with your existing Laravel project structure, requiring minimal configuration and setup.
  • Customizable Options: Provides flexible configuration settings to tailor the generator to your specific development requirements.

✅ Requirements

To use the Laravel Factory Seeder Generator, ensure that your environment meets the following requirements:

  • Laravel: This package requires Laravel 8.x or later.
  • PHP: Ensure that you are running PHP 8.1 or higher.
  • Faker: The package leverages the Faker library for data generation, which is included with Laravel.

🚀 Installation

To install the Laravel Factory Seeder Generator, follow these steps:

  1. Require the Package: Use Composer to add the package to your Laravel project:

    composer require danilowa/laravel-factory-seeder-generator
  2. Publish Configuration (optional): If your package includes configuration files, you can publish them to your application's config directory:

    php artisan vendor:publish --provider="Danilowa\LaravelFactorySeederGenerator\Providers\FactorySeederGeneratorServiceProvider"

🔧 How It Works

  1. Field Retrieval: The package scans your models to identify all fields listed in $fillable, garantindo que apenas os campos pretendidos sejam utilizados para geração de dados.

  2. Intelligent Data Generation: For each field in $fillable, the package generates relevant data using Laravel's Faker library.

  3. Utilization of Casts: If your model specifies casts, the package automatically generates suitable data types.

⚙️ Configuration

The configuration file allows you to customize the behavior of the generator. Here are the key settings you can modify:

  • Custom Attributes Active: Toggle this option to enable or disable custom attributes.

    'custom_attributes_active' => true,
  • Default Attributes Priority: When enabled, this setting takes precedence over the default Laravel casts.

    'custom_attributes_priority' => false,
  • Custom Attributes: Specify mappings for custom attributes.

    'custom_attributes' => [
        'price' => '$this->faker->randomFloat(2, 1, 1000)',
        'username' => '$this->faker->userName',
    ],
  • Include Relationships in Factories: This option allows you to include related models in the generated factories.

    'include_relationships' => true,
  • Custom Seeder Count: Set the default number of records to create when generating seeders.

    'custom_seeder_count' => 10,
  • Enable Logging: This option enables detailed logging for the generation process.

    'enable_logging' => false,

⚡ Command Overview

The package includes a variety of commands to facilitate the factory and seeder generation process:

  • GenerateFactory: Generates a factory for a specified model.
  • GenerateSeeder: Creates a seeder for a specified model.
  • GenerateFactoryAndSeederCommand: Combines functionalities of both commands.
  • GenerateFactoryAndSeederAllCommand: Automatically generates factories and seeders for all models in your application.

📜 Usage Examples

To generate all necessary files for models without factories and seeders, run:

php artisan make:a-all-factories-and-seeders --count=12

To generate factory and seeder files for specific models, use:

php artisan make:a-factories-and-seeders --count=14

To generate a factory and seeder for a particular model, execute:

php artisan make:a-factory {ModelName}
php artisan make:a-seeder {ModelName} --count=15

🚀 Advantages

  • Efficiency: Reduces the time spent on manual factory and seeder creation.
  • Consistency: Ensures that generated data is valid and consistent.
  • Flexibility: Customizable settings to adapt the package to your unique development needs.

✅ Conclusion

The Laravel Factory Seeder Generator is an essential tool for Laravel developers looking to optimize their workflow by automating factory and seeder creation.

🤝 Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Make your changes and commit them (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

📝 License

This package is licensed under the MIT License.

📬 Contact

For any questions or feedback, please reach out to:


Note: This package is currently under development.

About

Simplify database seeding with Laravel Factory Seeder Generator! Automatically create structured factories and seeders with intelligent data generation, customizable options, and seamless Laravel integration

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages