File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace LaracraftTech \LaravelUsefulAdditions \Commands ;
4+
5+ use Illuminate \Console \Command ;
6+ use Illuminate \Console \ConfirmableTrait ;
7+ use Illuminate \Support \Facades \DB ;
8+ use Illuminate \Support \Facades \Schema ;
9+
10+ class DBTruncateCommand extends Command
11+ {
12+ use ConfirmableTrait;
13+
14+ public $ signature = 'db:truncate ' ;
15+
16+ public $ description = 'Truncate all tables ' ;
17+
18+ public function handle (): int
19+ {
20+ if (! $ this ->confirmToProceed ()) {
21+ return 1 ;
22+ }
23+
24+ $ this ->components ->info ('Preparing database. ' );
25+
26+ collect (Schema::getAllTables ())->each (function ($ tableDefinition ) {
27+ $ table = current ($ tableDefinition );
28+ $ this ->components ->task ("Truncating table: $ table " , function () use ($ table ) {
29+ DB ::table ($ table )->truncate ();
30+ });
31+ });
32+
33+ $ this ->newLine ();
34+
35+ return self ::SUCCESS ;
36+ }
37+ }
Original file line number Diff line number Diff line change 22
33namespace LaracraftTech \LaravelUsefulAdditions ;
44
5+ use LaracraftTech \LaravelUsefulAdditions \Commands \DBTruncateCommand ;
56use Spatie \LaravelPackageTools \Package ;
67use Spatie \LaravelPackageTools \PackageServiceProvider ;
78
@@ -16,6 +17,7 @@ public function configurePackage(Package $package): void
1617 */
1718 $ package
1819 ->name ('laravel-useful-additions ' )
19- ->hasConfigFile ();
20+ ->hasConfigFile ()
21+ ->hasCommand (DBTruncateCommand::class);;
2022 }
2123}
You can’t perform that action at this time.
0 commit comments