Download the PHP package laragear/populate without Composer

On this page you can find all versions of the php package laragear/populate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package populate

Populate

Latest Version on Packagist Latest stable test run Codecov coverage Maintainability Sonarcloud Status Laravel Octane Compatibility

Populate your database with a supercharged, continuable seeder.

Become a sponsor

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

Requirements

Installation

You can install the package via Composer.

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

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

You will receive a Super Seeder with single seed() method, and two others one that will execute before and after.

[!TIP]

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

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

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.

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

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

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.

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

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.

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.

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.

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

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

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

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.

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

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

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

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.

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 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

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, 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.

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.

[!TIP]

Transactions use the db:seed command declared connection.

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.

Laravel Octane compatibility

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

Security

If you discover any security related issues, issue a Security Advisor

License

This specific package version is licensed under the terms of the MIT License, at time of publishing.

Laravel is a Trademark of Taylor Otwell. Copyright © 2011-2025 Laravel LLC.


All versions of populate with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/console Version 11.*|12.*
illuminate/database Version 11.*|12.*
illuminate/filesystem Version 11.*|12.*
illuminate/pipeline Version 11.*|12.*
illuminate/support Version 11.*|12.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package laragear/populate contains the following files

Loading the files please wait ....