Created
November 20, 2015 11:05
-
-
Save andyg1/4d6ee6de61b031c13d65 to your computer and use it in GitHub Desktop.
Truncating Laravel tables before seeding them
This file contains hidden or 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
Thanks