io-digital/truncate-tables

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

1.0.1 2021-05-02 02:22 UTC

This package is auto-updated.

Last update: 2024-11-06 20:40:28 UTC


README

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.