cyber-duck/seeder-generator

Generate seeders automatically from Laravel Telescope
1,143 3
Install
composer require cyber-duck/seeder-generator
PHP:^7.4
License:MIT
Last Updated:Sep 8, 2023
Links: GitHub  ·  Packagist
Maintainer: cyber-duck

Seeder Generation for Laravel

This is an experimental package to generate seeders from Laravel Telescope entries.

You can contribute by testing it, adding more automate tests, documentation or features!

Installation

Require the package with Composer as a dev dependency:

composer require cyber-duck/seeder-generator --dev

If you are NOT using the Laravel package auto-discovery feature, please add the following service-provider to config/app.php

[
    'providers' => [
        // ...
        \CyberDuck\Seeder\Providers\SeederGeneratorProvider::class,
    ]
];

Usage

  1. Run this command to get the last Telescope entry:

php artisan cyber-duck:telescope:last-entry-uuid

You will receive a response like:

The last entry uuid is: 937a170d-1aa2-495c-92e2-33389841bab5 (2021-05-20 15:50:20)

  1. Perform the steps you want to reproduce (by interacting with the app manually or automatically with Cypress, Laravel Dusk, etc.)

  2. Generate the seeder:

php artisan cyber-duck:seeder:generate [MySeederClassNameHere] [uuid-entry-here]

Configuration options

This package will do its best to work without any configuration option, but you can also:

Map tables to models:

// config/seeder-generator.php
[
    //...
    'tablesDictionary' => [
        'my_table' => 'MyModel'
    ],
];

Map static values to variables:

You can map static values of foreign keys to variables:

For example, everytime a query includes the field 'user_id' as a field or condition, it will be map to a $userN variable, where N will be dynamic, depending on the user ID.

[
    //...
    'expectedVariables' => [
        'user_id' => 'user'
    ],
];

You can also map polymorphic relationships where the variable should change depending on the model:

[
    //...
    'expectedVariables' => [
        'addressable_id' => 'morph:addressable_type'
    ],
    'morphVariables' => [
        'App\Models\User' => 'user',
    ],
];

Related Packages

gabrieloliverio/laravel5-generators

Database metadata-based generators for Laravel 5

1
erirk/paypalpayment

laravel-paypalpayment is simple package help you process direct credit card paym...

0
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444