TestCommand.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Repositories\Models\Base\Admin;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Hash;
  7. /**
  8. * Class PresenterCommand
  9. * @package Prettus\Repository\Generators\Commands
  10. * @author Anderson Andrade <contato@andersonandra.de>
  11. */
  12. class TestCommand extends Command
  13. {
  14. /**
  15. * The name of command.
  16. *
  17. * @var string
  18. */
  19. protected $name = 'mead:test';
  20. /**
  21. * The description of command.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'test';
  26. /**
  27. * The type of class being generated.
  28. *
  29. * @var string
  30. */
  31. protected $type = 'permission';
  32. /**
  33. * Execute the command.
  34. *
  35. * @return void
  36. * @see fire()
  37. */
  38. public function handle()
  39. {
  40. $this->line('ok');
  41. }
  42. public function clearDB()
  43. {
  44. DB::statement('SET FOREIGN_KEY_CHECKS = 0'); // 禁用外键约束
  45. DB::table('base_admins')->truncate();
  46. DB::table('base_model_has_roles')->truncate();
  47. DB::table('car_applies')->truncate();
  48. DB::table('car_apply_logs')->truncate();
  49. DB::table('car_bills')->truncate();
  50. DB::table('car_grades')->truncate();
  51. DB::table('car_order_logs')->truncate();
  52. DB::table('car_orders')->truncate();
  53. DB::table('car_shops')->truncate();
  54. DB::table('base_users')->truncate();
  55. DB::statement('SET FOREIGN_KEY_CHECKS = 1'); // 启用外键约束
  56. $admin = Admin::query()->create([
  57. 'username' => 'superadmin',
  58. 'name' => '超级管理员',
  59. 'mobile' => '15225006562',
  60. 'type' => '1',
  61. 'email' => '751066209@qq.com',
  62. 'password' => Hash::make('Q1w2e3r4!'),
  63. ]);
  64. $admin->syncRoles('admin');
  65. }
  66. }