LaravelPackages.net
Acme Inc.
Toggle sidebar
strawberrydev/wimd

Where Is My Data - A Laravel seeder monitoring package

9
1
v2.1.4-alpha
About strawberrydev/wimd

strawberrydev/wimd is a Laravel package for where is my data - a laravel seeder monitoring package. It currently has 1 GitHub stars and 9 downloads on Packagist (latest version v2.1.4-alpha). Install it with composer require strawberrydev/wimd. Discover more Laravel packages by strawberrydev or browse all Laravel packages to compare alternatives.

Last updated

Cover

Latest Version on Packagist Total Downloads License

Introduction

Have you ever wondered where your data is while seeding? Me too. That's why there's WIMD (Where Is My Data), a Laravel package that enhances your database seeding process with monitoring. It provides real-time tracking of seeding performance, detailed metrics, and insightful reporting to help you optimize your database seeding operations.

Warning

This is the first release and not a stable version. It is meant to showcase the current state of the project and its progress. Updates will be made.
Some features don't work yet and will be properly implemented in future updates.

Requirements

  • PHP 8.1+
  • Laravel 9.0+

Installation

You can install the package via composer:

composer require strawberrydev/wimd

Or for alpha version

composer require strawberrydev/wimd:"dev-main"

Configuration

Publish the configuration file using:

php artisan vendor:publish --tag=wimd-config

This will create a config/wimd.php file where you can customize the package behavior.

Usage

DatabaseSeeder

<?php

namespace Database\Seeders;

use Wimd\Template\WimdDatabaseSeeder;

class DatabaseSeeder extends WimdDatabaseSeeder
{
    public function run()
    {
        $this->call([
            UserSeeder::class,
            CategoriesSeeder::class,
            ProductsSeeder::class,
            TagsSeeder::class,
            ProductTagSeeder::class,
            UserDetailsSeeder::class,
            ReviewsSeeder::class,
        ]);

        // Optional
        $this->displayWimdReport();
    }
}

showcase

Use this line if you want to manually display the report (not shown by default unless using the specific command):

$this->displayWimdReport();

Seeder

Extend Wimd\Template\WimdSeeder instead of Laravel's Seeder:

<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Wimd\Template\WimdSeeder;

class UserSeeder extends WimdSeeder
{
    protected function prepare(): void
    {
        $this->totalItems = 1000;
        $this->fullItems = 1000000;
        $this->lightItems = 250;
        $this->batchSize = 77;
    }

    protected function seed(): void
    {
        $admin = [
            'name' => 'Admin User',
            'email' => '[email protected]',
            'password' => Hash::make('password'),
            'created_at' => now(),
            'updated_at' => now(),
        ];

        $this->insertItem('users', $admin);

        $this->createWithFactory(User::class, $this->totalItems - 1);
    }
}

Advanced Usage

Using the Built-in Batch Methods

batchInsert()

$this->batchInsert('users', $usersArray, $batchSize);

insertItem() and insertItemAndGetId()

$this->insertItem('users', $userData);

createWithFactory()

$this->createWithFactory(User::class, 50);

License

The MIT License (MIT). Please see License File for more information.

Footer

Comments