-
-
Save f-giftagram/f63aff521c98b30dbe254bd31b400fda to your computer and use it in GitHub Desktop.
Truncating Laravel tables before seeding them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Seeder; | |
use Illuminate\Database\Eloquent\Model; | |
class DatabaseSeeder extends Seeder | |
{ | |
protected $toTruncate = ['users']; | |
public function run() | |
{ | |
Model::unguard(); | |
foreach($this->toTruncate as $table) { | |
DB::table($table)->truncate(); | |
} | |
$this->call(UsersTableSeeder::class); | |
Model::reguard(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment