PHP code example of ruzaik11 / laravel-seeder-tracker

1. Go to this page and download the library: Download ruzaik11/laravel-seeder-tracker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ruzaik11 / laravel-seeder-tracker example snippets




namespace Database\Seeders;

use Ruzaik\SeederTracker\Seeders\TrackableSeeder;
use App\Models\User;

class UsersTableSeeder extends TrackableSeeder
{
    protected function seedData()
    {
        // Your seeding logic
        $users = User::factory(100)->create();
        
        // Return metadata for tracking
        return [
            'users_created' => $users->count(),
            'admin_users' => $users->where('is_admin', true)->count(),
        ];
    }
}

use Ruzaik\SeederTracker\Traits\SeederHelper;

class ProductionDataSeeder extends TrackableSeeder
{
    use SeederHelper;
    
    protected function seedData()
    {
        // Only run in specific environments
        return $this->runInEnvironments(['production', 'staging'], function () {
            // Production-specific seeding logic
            return ['production_data_created' => true];
        });
    }
}

protected function seedData()
{
    $startCount = $this->getTableCount('products');
    
    // Batch insert for better performance
    Product::insert($this->generateProductData(1000));
    
    return [
        'products_created' => $this->getTableCount('products') - $startCount,
        'batch_size' => 1000,
        'optimization' => 'batch_insert_used',
    ];
}

protected function seedData()
{
    return DB::transaction(function () {
        // All seeding logic in transaction
        $categories = Category::createMany($this->categoryData());
        $products = Product::createMany($this->productData());
        
        return [
            'categories_created' => count($categories),
            'products_created' => count($products),
            'transaction_safe' => true,
        ];
    });
}

return [
    // Database table for tracking
    'table' => 'seeder_tracking',
    
    // Enable automatic tracking
    'auto_track' => true,
    
    // Prevent duplicate executions
    'prevent_duplicates' => env('SEEDER_PREVENT_DUPLICATES', true),
    
    // Strict environments (always prevent duplicates)
    'strict_environments' => ['production'],
];
bash
php artisan vendor:publish --provider="Ruzaik\SeederTracker\SeederTrackerServiceProvider"
php artisan migrate
bash
php artisan db:seed --class=UsersTableSeeder
# ✅ Seeder UsersTableSeeder executed successfully in 1,234ms
bash
php artisan seeder:status
bash
# Show performance insights
php artisan seeder:performance

# Limit results
php artisan seeder:performance --limit=5
bash
php artisan seeder:performance