mrbenosborne/laravel-database-seed-trait

Seed a database within Laravel tests just by using a trait.

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/mrbenosborne/laravel-database-seed-trait

1.0.1 2020-06-16 16:13 UTC

This package is auto-updated.

Last update: 2025-09-29 02:43:16 UTC


README

Seed a database within Laravel tests just by using a trait.

Install

composer require mrbenosborne/laravel-database-seed-trait

Example

The trait will use the default seeder "DatabaseSeeder", and the default connection specified in your app config.

Before

<?php

namespace Tests\Feature;

use DatabaseSeeder;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class AuthControllerTest extends TestCase
{
    use DatabaseMigrations;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed(DatabaseSeeder::class);
    }
}

After

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Database\SeedDatabase;
use Tests\TestCase;

class AuthControllerTest extends TestCase
{
    use DatabaseMigrations, SeedDatabase;
}