PHPackages                             laragear/populate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. laragear/populate

ActiveLibrary

laragear/populate
=================

Populate your database with a supercharged, continuable seeder

v2.0.0(2mo ago)8611.8k↓30.8%1MITPHPPHP ^8.3CI passing

Since Apr 25Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Laragear/Populate)[ Packagist](https://packagist.org/packages/laragear/populate)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-populate/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (4)Dependencies (14)Versions (9)Used By (0)

Populate
========

[](#populate)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ce20c49ebb6f06bcc14b9ab38d1ae87512c1bd16843aa1467aa9c9d71e02db35/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f706f70756c6174652e737667)](https://packagist.org/packages/laragear/populate)[![Latest stable test run](https://github.com/Laragear/Populate/actions/workflows/php.yml/badge.svg)](https://github.com/Laragear/Populate/actions/workflows/php.yml)[![Codecov coverage](https://camo.githubusercontent.com/7302e0880d808f96ad6a584dda350bb31867a876ce08d2b7de5e5e543c6124b8/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f506f70756c6174652f67726170682f62616467652e7376673f746f6b656e3d636b313770425036565a)](https://codecov.io/gh/Laragear/Populate)[![Maintainability](https://camo.githubusercontent.com/60b8498be100920b10bf4704a90b35798a37a2bbb68696073c54c9718326a2d4/68747470733a2f2f716c74792e73682f6261646765732f33346533643535662d303663642d346136632d623864382d3964323163636262636662372f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/Populate)[![Sonarcloud Status](https://camo.githubusercontent.com/564ff9f9a738963f994d51c62fbe5a3119bb9d2d008f6fa7e70b5607dce40aff/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f506f70756c617465266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_Populate)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/13.x/octane#introduction)

Populate your database with a supercharged, continuable seeder.

```
use Laragear\Populate\Seeder;

class UserSeeder extends Seeder
{
    public function seedNormalUsers()
    {
        //
    }

    public function seedBannedUsers()
    {

    }
}
```

Become a sponsor
----------------

[](#become-a-sponsor)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable.

Requirements
------------

[](#requirements)

- PHP 8.3 or later
- Laravel 12 or later

Installation
------------

[](#installation)

You can install the package via Composer.

```
composer require laragear/populate
```

How does this work?
-------------------

[](#how-does-this-work)

Laravel's Seeding system is very antique and basic. This library supercharges the seeding system of Laravel to make it more friendly to develop and run.

By *hijacking* the default Seeder with a better one, we can supercharge the seed system to allow per-step seeding, skipping and *continuable* seeding, without sacrificing on its normal features, and keeping compatibility with classic seeding classes.

Set up
------

[](#set-up)

You may create a super-seeder using `make:super-seeder` Artisan command, and the name of the seeder.

```
php artisan make:super-seeder UserSeeder
```

You will receive a *Super Seeder* with single `seed()` method, and two others one that will execute [before and after](#before--after).

```
namespace Database\Seeders:

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Laragear\Populate\Seeder;

class UserSeeder extends Seeder
{
    /**
     * Run logic before executing the seed steps.
     */
    public function before(): void
    {
        // if (false) {
        //     $this->skip();
        // }
    }

    /**
     * Populate the database with records.
     */
    public function seed(): void
    {
        //
    }

    /**
     * Run logic after executing the seed steps.
     */
    public function after(): void
    {
        //
    }
}
```

Tip

If you already created your application seeders, replace the `Illuminate\Database\Seeder` import to `Laragear\Populate\Seeder`.

```
namespace Database\Seeders;

// use Illuminate\Database\Seeder;
use Laragear\Populate\Seeder;

class UserSeeder extends Seeder
{
    //..
}
```

If you want to change the seeder stub, you may publish it through the `vendor:publish` Artisan command under the `stub` tag.

```
php artisan vendor:publish --provider=Laragear\Populate\PopulateServiceProvider --tag=stubs
```

Usage
-----

[](#usage)

Instead of using the `run()` method in your seeder, this library's seeders use the concept of **Seed Steps**. A Seed Step is just a public method that starts with `seed`, or uses the `Laragear\Populate\Attributes\SeedStep` attribute, named to briefly describe the records that are being inserted.

The container instantiates the Seeder and also calls each Seed Step, so you can use Dependency Injection as arguments anywhere you require.

```
namespace Database\Seeders;

use Database\Factories\UserFactory;
use Laragear\Populate\Attributes\SeedStep;
use Laragear\Populate\Seeder;
use App\TicketGenerator;

class UserSeeder extends Seeder
{
    public function __construct(protected TicketGenerator $ticket)
    {
        // ...
    }

    public function seedNormalUsers(UserFactory $users)
    {
        $users->count(5)->create(['ticket' => $this->ticket->generate()]);
    }

    public function seedVipUsers(UserFactory $users)
    {
        $users->vip()->count(3)->create();
    }

    #[SeedStep]
    public function bannedUsers(UserFactory $users)
    {
        $users->banned()->count(2)->create(['ticket' => $this->ticket->generate()]);
    }
}
```

For convenience, a Seed Step will persist all records if these return a Model Factory, a Collection of Models or a single Model.

```
use Database\Factories\UserFactory;

public function seedNormalUsers(UserFactory $users)
{
    return $users->count(5);
}
```

When the seeder is called, each Seed Step will be output to the console like this:

```
php artisan db:seed

INFO Seeding database.

Database\Seeders\UserSeeder ...................................... RUNNING
~ Seed normal users ................................................. DONE
~ Seed banned users ................................................. DONE
Database\Seeders\UserSeeder .................................. 107 ms DONE

```

### Custom Seed Step naming

[](#custom-seed-step-naming)

Each Seed Step is described in the console output as *First word capitalized*, so a Seed Step function called `seedVipUsers` will be displayed as `Seed vip users`. If you total control, the `SeedStep` attribute accepts an argument to change the output description.

```
use Laragear\Populate\Attributes\SeedStep;

#[SeedStep(as: 'Seed non-authorized users')]
public function bannedUsers(UserFactory $users)
{
    $users->banned()->count(2)->create(['ticket' => $this->ticket->generate()]);
}
```

That will output the step as named, verbatim:

```
php artisan db:seed

INFO Seeding database.

Database\Seeders\UserSeeder ...................................... RUNNING
~ Seed normal users ................................................. DONE
~ Seed non-authorized users ......................................... DONE
Database\Seeders\UserSeeder .................................. 107 ms DONE

```

### Calling with arguments

[](#calling-with-arguments)

When calling other seeders inside a Seed Step, you may use the usual `$this->call()` method and its variants. Classic seeders will execute their `run()` method as always if the method exists.

When doing calling a Super Seeder, you may set an array of arguments for each seed task by issuing their name as a key and the arguments as an array. This can be great when a seeder contains a Seed Steps that would require parameters to properly populate records on the database.

```
use Database\Factories\UserFactory;
use Database\Factories\CommentFactory;
use Laragear\Populate\Seeder;

class UserSeeder extends Seeder
{
    // ...

    public function seedMutedUsers(UserFactory $factory)
    {
        $users = $factory->muted()->create(3);

        $this->call(CommentSeeder::class, [
            'seedModeratedComment' => ['users' => $users],
        ]);
    }
}

class CommentSeeder extends Seeder
{
    public function seedModeratedComment(CommentFactory $comments, $users)
    {
        foreach ($users as $user) {
            $comments->for($user)->moderated()->create();
        }
    }
}
```

### Before &amp; After

[](#before--after)

When calling a seeder, you may implement the `before()` and `after()` methods to run logic before the Seed Steps are executed, and after all are done with, respectively. As with Seed Steps, these are called through the Service Container.

```
use Illuminate\Contracts\Config\Repository;use Illuminate\Contracts\Routing\UrlGenerator;
use Laragear\Populate\Seeder;

class CommentSeeder extends Seeder
{
    public function before(UrlGenerator $url)
    {
        // ...
    }

    public function after(Repository $config)
    {
        // ...
    }
}
```

### On Error

[](#on-error)

For better control on Seed Steps that returns errors, you may implement the `onError()` method that receives the offending exception. It's great to use for cleaning artifacts before stopping the seeding operation.

```
use Laragear\Populate\Seeder;

class CommentSeeder extends Seeder
{
    public function onError($exception)
    {
        // ...
    }
}
```

You may also return or throw another exception to replace the previous exception.

```
public function onError($exception)
{
    return new RuntimeException('The seeder failed', previous: $exception);
}
```

### Skipping

[](#skipping)

Laragear's Seeders support skipping either a Seed Step or the whole Seeder. Both are done through the `skip()` method.

#### Skipping a Seed Step

[](#skipping-a-seed-step)

To skip a Seed Step, you only need to call the `skip()` method inside it.

```
use App\Models\User;
use Database\Factories\UserFactory;

public function seedBannedUsers(UserFactory $user)
{
    if (User::query()->banned()->exists()) {
        $this->skip();
    }

    // ...
}
```

It will output something like this:

```
php artisan db:seed

INFO Seeding database.

Database\Seeders\UserSeeder ...................................... RUNNING
~ Seed normal users ................................................. DONE
~ Seed non-authorized users ...................................... SKIPPED
Database\Seeders\UserSeeder .................................. 107 ms DONE

```

The `skip()` method supports using a reason for skip which will be displayed in the console output.

```
use App\Models\User;

if (User::query()->banned()->exists()) {
    $this->skip('There are already banned users in the database');
}
```

```
Database\Seeders\UserSeeder ...................................... RUNNING
~ Seed normal users ................................................. DONE
~ Seed non-authorized users ...................................... SKIPPED
  There are already banned users in the database
Database\Seeders\UserSeeder .................................. 107 ms DONE

```

Tip

If transactions are not disabled, the `skip()` method will trigger a rollback wherever is called inside a Seed Step.

#### Skipping a Seeder

[](#skipping-a-seeder)

To skip a seeder completely, you may use the `skip()` method on the [`before()`](#before--after) method, which runs before any Seed Step is executed. As with the Seed Steps, you may also include a skip reason.

```
use App\Models\Comment;
use Laragear\Populate\Seeder;

class CommentSeeder extends Seeder
{
    public function before()
    {
        if (Comment::query()->exists()) {
            $this->skip('There are already comments in the database')
        }
    }
}
```

```
Database\Seeders\CommentSeeder ................................... RUNNING
Database\Seeders\CommentSeeder ................................... SKIPPED
  There are already comments in the database
Database\Seeders\CommentSeeder ................................. 0 ms DONE

```

Continue Seeding
----------------

[](#continue-seeding)

Sometimes your Seeding command may fail for hard errors, leaving orphaned or incomplete records in your database and forcing you to seed the whole database again.

To avoid this, Laragear Populate allows a previous incomplete seeding to *continue*. Call the `db:seed` command with the `--continue` option, and if the seeding fails it will save the progress for the next attempt.

```
php artisa db:seed --continue
```

The seeding continuation is tied to the Seeder you call in the command, which by default is `Database\Seeders\DatabaseSeeder`.

Tip

When using the `--continue` options, [transactions](#disable-transactions) will be automatically turned on.

The console output will mark the seed step as `CONTINUE` if the step it already ran.

```
php artisan db:seed

INFO Seeding database.

Database\Seeders\UserSeeder ...................................... RUNNING
~ Seed normal users ............................................. CONTINUE
~ Seed non-authorized users ......................................... DONE
Database\Seeders\UserSeeder ................................... 32 ms DONE

```

### Recovering from Unique Constraints Violations

[](#recovering-from-unique-constraints-violations)

Sometimes a Seed Step may throw a *Unique Constraints Violation* exception, which happens when trying to insert a value that already exists on *unique* column, like primary keys. It's not too common, but it usually happens when a random generator mistakenly repeats a value, like emails or text.

[If transactions are not disabled](#disable-transactions), the Populator will retry the Seed Step again, showing the retry on the console. If the error persists, it will be thrown.

```
php artisan db:seed

INFO Seeding database.

Database\Seeders\UserSeeder ...................................... RUNNING
~ Seed normal users ............................................. CONTINUE
~ Seed non-authorized users ................................. RETRY UNIQUE
~ Seed non-authorized users ......................................... DONE
Database\Seeders\UserSeeder ................................... 32 ms DONE

```

You can set the `retryUnique` property of the `SeedStep` attribute to any number of retries from the default `1`. Alternatively, setting it to `false` or `0` will disable it.

```
use Laragear\Populate\Attributes\SeedStep;

#[SeedStep(retryUnique: false)]
public function bannedUsers
{
    // ...
}
```

### Disable transactions

[](#disable-transactions)

Laragear Populate's Seeders wraps each Seed Step into its own transaction using the default database connection. This means that, when a Seed Step fails, all database operations inside that method are rolled back.

If you want to disable transactions, you may use set the `$usesTransactions` property to `false`. In that case, if you require seed steps to be skipped, it's recommended to skip at the start of the method.

```
use App\Models\Comment;
use Laragear\Populate\Seeder;

class CommentSeeder extends Seeder
{
    public bool $usesTransactions = false;

    public function seedGuestComments()
    {
        if (Comment::query()->guest()->exists()) {
            $this->skip('There is already guest comments in the database');
        }

        // ...
    }

    // ...
}
```

Tip

Transactions use the `db:seed` command declared connection.

Injecting Factory instances
---------------------------

[](#injecting-factory-instances)

If you're injecting factory instances into a seed step, you will find that the `configure()` method of the state won't be called since it's only set when using `Model::factory()` or `ModelFactory::new()` static methods.

If your Factory overrides the `configure()` method, you're encouraged to manually instance the factory inside your seeder.

```
use App\Models\Comment;
use Laragear\Populate\Seeder;

class CommentSeeder extends Seeder
{
    public function seedGuestComments()
    {
        $factory = Comment::factory();

        // ...
    }

    // ...
}
```

Laravel Octane compatibility
----------------------------

[](#laravel-octane-compatibility)

- There are no singletons using a stale app instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- There are no static properties written during a request.

There should be no problems using this package with Laravel Octane.

Security
--------

[](#security)

If you discover any security-related issues, issue a [Security Advisor](https://github.com/Laragear/Populate/security/advisories/new)

License
=======

[](#license)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at the time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011–2026 Laravel LLC.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance86

Actively maintained with recent releases

Popularity38

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~79 days

Total

6

Last Release

71d ago

Major Versions

1.x-dev → 2.x-dev2026-03-08

PHP version history (2 changes)v1.0.0PHP ^8.2

2.x-devPHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5141911?v=4)[Italo](/maintainers/DarkGhostHunter)[@DarkGhostHunter](https://github.com/DarkGhostHunter)

---

Top Contributors

[![DarkGhostHunter](https://avatars.githubusercontent.com/u/5141911?v=4)](https://github.com/DarkGhostHunter "DarkGhostHunter (14 commits)")

### Embed Badge

![Health badge](/badges/laragear-populate/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-populate/health.svg)](https://phpackages.com/packages/laragear-populate)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
