Laravel package to generate seeders from an existing database.
zainularfeen/laravel-seeder-generator is a Laravel package for laravel package to generate seeders from an existing database..
It currently has 1 GitHub stars and 12 downloads on Packagist.
Install it with composer require zainularfeen/laravel-seeder-generator.
Discover more Laravel packages by zainularfeen
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Seeder Generator is a powerful package that allows you to generate seeders from existing database tables with hardcoded data. This is extremely useful for creating backups or replicating database states across different environments.
β
Automatically generates seeders from database tables
β
Handles large datasets with chunking
β
Option to overwrite existing seeders
β
Efficient memory handling using Laravel's cursor
β
Easy installation and simple usage
β
Supports Laravel 9+
You can install the package via Composer:
composer require zainularfeen/laravel-seeder-generator --dev
The package will be auto-discovered in Laravel. If not, you can manually register the Service Provider:
// config/app.php
'providers' => [
Zainularfeen\SeederGenerator\SeederGeneratorServiceProvider::class,
];
Run the following command to generate seeders for all database tables:
php -d memory_limit=-1 artisan generate:seeders
If your database has a large number of records, you can control how many rows are processed at a time using the --chunk option:
php -d memory_limit=-1 artisan generate:seeders --chunk=500
By default, if a seeder file already exists, it will not be overwritten. Use --force to regenerate all seeders:
php -d memory_limit=-1 artisan generate:seeders --force
You can combine options like this:
php -d memory_limit=-1 artisan generate:seeders --chunk=1000 --force
migrations and telescope_entries.cursor() to avoid memory issues.database/seeders directory.php artisan db:seed --class=YourTableSeeder to seed your database.After running the command, it generates seeder files inside database/seeders:
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class UsersSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
['id' => 1, 'name' => 'John Doe', 'email' => '[email protected]', 'created_at' => now(), 'updated_at' => now()],
['id' => 2, 'name' => 'Jane Smith', 'email' => '[email protected]', 'created_at' => now(), 'updated_at' => now()],
]);
}
}
Once the seeders are generated, you can use Laravel's built-in seeding commands:
php artisan db:seed --class=UsersSeeder
To seed all generated seeders at once:
php artisan db:seed
β "Seeder already exists for users. Use --force to overwrite."
Solution: Use the --force flag:
php artisan generate:seeders --force
β "PHP Fatal error: Allowed memory size exhausted"
Solution: Run the command with unlimited memory:
php -d memory_limit=-1 artisan generate:seeders
This package is open-source software licensed under the MIT license.
Pull requests are welcome! If you find a bug or have a feature request, feel free to open an issue.
Developed by Zain Ul Arfeen
GitHub: zainularfeen