Skip to content

A Laravel package to easily truncate database tables when running seeder files

License

Notifications You must be signed in to change notification settings

io-digital/truncate-tables

Repository files navigation

A Laravel package to easily truncate database tables when running seeder files

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require io-digital/truncate-tables

Usage

In database/seeders/DatabaseSeeder.php:

<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use IoDigital\TruncateTable\TruncateTable;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        TruncateTable::fromArrays([
            'users',
            'posts'
        ])->clean();
        
        // Or like the following
        
        TruncateTable::fromArrays([
            'users',
            'posts'
        ], [
            UserTableSeeder::class,
            PostTableSeeder::class,
        ])->cleanAndSeed();
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.