PHPackages                             sleeping-owl/seeder - 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. [Database &amp; ORM](/categories/database)
4. /
5. sleeping-owl/seeder

ActiveLibrary[Database &amp; ORM](/categories/database)

sleeping-owl/seeder
===================

Package to create simple seeders with ability to lock/unlock tables

1.0.2(11y ago)326MITPHPPHP &gt;=5.4.0

Since Mar 1Pushed 11y ago1 watchersCompare

[ Source](https://github.com/sleeping-owl/seeder)[ Packagist](https://packagist.org/packages/sleeping-owl/seeder)[ RSS](/packages/sleeping-owl-seeder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Package to create simple seeders with ability to lock/unlock tables
-------------------------------------------------------------------

[](#package-to-create-simple-seeders-with-ability-to-lockunlock-tables)

[![Latest Stable Version](https://camo.githubusercontent.com/1487e2a11dc47c89235c80d814da39e575318636c3348a59a502e269462e8dd6/68747470733a2f2f706f7365722e707567782e6f72672f736c656570696e672d6f776c2f7365656465722f762f737461626c652e737667)](https://packagist.org/packages/sleeping-owl/with-join)[![License](https://camo.githubusercontent.com/d3b8b2f12bc0b542310710a313746dbba9b98408d25d07b80d05d948ba4442d3/68747470733a2f2f706f7365722e707567782e6f72672f736c656570696e672d6f776c2f7365656465722f6c6963656e73652e737667)](https://packagist.org/packages/sleeping-owl/with-join)

Overview
--------

[](#overview)

This package will allow you to write simple seeders:

```
use SleepingOwl\Seeder\DataSeeder;
use SleepingOwl\Seeder\Seeder as SleepingOwlSeeder;

class DatabaseSeeder extends Seeder
{

	public function run()
	{
		 # set global locale (default is en_US)
		SleepingOwlSeeder::setDefaultLocale('de_DE');

		 # set global entries count (default is 10)
		SleepingOwlSeeder::setDefaultTimes(10);

		 # truncate all tables before seeding (default is off)
		SleepingOwlSeeder::truncateAll();

		# seed Country model
		SleepingOwlSeeder::model(Country::class)
			->seed(function (DataSeeder $schema)
			{
				$schema->title->unique()->country;
			});

		# seed Company model
		SleepingOwlSeeder::model(Company::class)
			->seed(function (DataSeeder $schema)
			{
				$schema->title->unique()->company;
				$schema->address->streetAddress;
				$schema->phone->phoneNumber;
			});

		# seed Contact model
		SleepingOwlSeeder::model(Contact::class)
			->seed(function (DataSeeder $schema)
			{
				$schema->firstName->firstName;
				$schema->lastName->lastName;
				$schema->birthday->dateTimeThisCentury;
				$schema->phone->phoneNumber;
				$schema->address->address;
				$schema->country_id->optional(0.9)->anyOf(Country::class);
				$schema->comment->paragraph(5);
			});

		# seed company_contact table
		SleepingOwlSeeder::table('company_contact')
			->ignoreExceptions()
			->seed(function ($schema)
			{
				$schema->company_id->anyOf(Company::class);
				$schema->contact_id->anyOf(Contact::class);
			});
	}

}
```

And adds 2 new commands:

1. `php artisan seeder:lock  --all` — lock table from any changes (table data will be saved and restored after reseeding).
2. `php artisan seeder:unlock  --all` — unlock table for random seeding.

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

[](#installation)

1. Require this packages in your composer.json and run composer update:

    ```
    "fzaninotto/faker": "1.5.*@dev",
    "sleeping-owl/seeder": "1.*"

    ```
2. After composer update, add service providers to the `config/app.php`

    ```
    'SleepingOwl\Seeder\SeederServiceProvider',

    ```
3. That's all.

Seeding
-------

[](#seeding)

1. Import classes:

    ```
    use SleepingOwl\Seeder\DataSeeder;
    use SleepingOwl\Seeder\Seeder as SleepingOwlSeeder;
    ```
2. Add seeding rule for table or model:

    ```
    SleepingOwlSeeder::table('table')->…
    # or
    SleepingOwlSeeder::model(\App\MyModel::class)->…
    ```
3. Configure seeding rule (you can configure it globally, see details in "Global Configuration"):

    ```
    SleepingOwlSeeder::table('table')
    	->truncate() # delete all data before seeding (default is off)
    	->locale('de_DE') # locale for this seed (default is en_US)
    	->times(100) # entities count to insert (default is 10)
    	->ignoreExceptions() # ignore query exceptions (default is off)
    	->...
    ```
4. Configure seeding schema (see details in "Schema Configuration"):

    ```
    SleepingOwlSeeder::table('table')
    	->…
    	->seed(function (DataSeeder $schema)
    	{
    		$schema->title->unique()->firstName;
    		$schema->country()->country;
    		$schema->field('my_field')->optional(0.9)->phoneNumber;
    	});
    ```
5. Now you can use default command `php artisan db:seed` and new `seeder:lock`/`seeder:unlock` commands.

Global Configuration
--------------------

[](#global-configuration)

You can configure seeding settings globally:

```
SleepingOwlSeeder::setDefaultLocale('de_DE');
SleepingOwlSeeder::setDefaultTimes(100);
SleepingOwlSeeder::truncateAll();
SleepingOwlSeeder::setDefaultIgnoreExceptions(true);
```

This configuration will be used as default for every seeder. Seeder configuration will override global configuration:

```
SleepingOwlSeeder::setDefaultTimes(100);

SleepingOwlSeeder::table('table')
	->times(5) # this configuration has higher priority
	->...
```

Schema Configuration
--------------------

[](#schema-configuration)

### Add Field to the Schema

[](#add-field-to-the-schema)

You must provide schema for seeding. There is 3 ways to add field to the schema:

1. `$schema->field('my_field')`
2. `$schema->my_field`
3. `$schema->my_field()`

All these 3 ways will add field `my_field` to the schema.

### Provide Rules for Seeding the Field

[](#provide-rules-for-seeding-the-field)

You must use [fzaninotto/faker](https://github.com/fzaninotto/Faker) package rules:

```
 # "phone" will be random phone number
 # "->phone" is field name
 # "->phoneNumber" is seeding rule
$schema->phone->phoneNumber;

 # "my_field" will be unique sentence with 6 words
$schema->my_field->unique()->sentence(6);

 # "country_title" will be country title in 90% cases and null in other 10%
$schema->country_title->optional(0.9)->country;

 # "post_id" will be id of any \App\Post entity
$schema->post_id->anyOf(\App\Post::class);

 # you can use your custom function for getting value for seeding
$schema->my_other_field->call(function ()
{
	return mt_rand(0, 10);
})

 # "int_field" will be random element from "$my_array"
$my_array = [1, 2, 3, 4];
$schema->int_field->randomElement($my_array);
```

Lock/Unlock Table Seeding
-------------------------

[](#lockunlock-table-seeding)

### Locking

[](#locking)

You can lock table seeding. This command will save table state and restores it with every seeding call.

You can lock one table:

```
php artisan seeder:lock table_name
```

Or all tables:

```
php artisan seeder:lock --all
```

### Unlocking

[](#unlocking)

This command will delete table saved state and restores default behaviour.

```
php artisan seeder:unlock table_name
```

or

```
php artisan seeder:unlock --all
```

Support Library
---------------

[](#support-library)

You can donate via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AXJMWMRPCBGVA) or in BTC: 13k36pym383rEmsBSLyWfT3TxCQMN2Lekd

Copyright and License
---------------------

[](#copyright-and-license)

Package was written by Sleeping Owl for the Laravel framework and is released under the MIT License. See the LICENSE file for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~0 days

Total

3

Last Release

4096d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/da62224c5896d50a9def476b8bb1f404457e03540718205587bf666bf4ff94dc?d=identicon)[sleeping-owl](/maintainers/sleeping-owl)

---

Top Contributors

[![sleeping-owl](https://avatars.githubusercontent.com/u/9197310?v=4)](https://github.com/sleeping-owl "sleeping-owl (5 commits)")

---

Tags

laraveldatabaseeloquentseeder

### Embed Badge

![Health badge](/badges/sleeping-owl-seeder/health.svg)

```
[![Health](https://phpackages.com/badges/sleeping-owl-seeder/health.svg)](https://phpackages.com/packages/sleeping-owl-seeder)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[czim/laravel-filter

Filter for Laravel Eloquent queries, with support for modular filter building

8973.0k3](/packages/czim-laravel-filter)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[eusonlito/laravel-database-cache

Cache Database Query results on Laravel Query Builder or Eloquent

194.2k](/packages/eusonlito-laravel-database-cache)

PHPackages © 2026

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