PageRenderTime 30ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/database/seeds/Access/UserTableSeeder.php

https://gitlab.com/Ankit77/motiv8
PHP | 55 lines | 44 code | 6 blank | 5 comment | 8 complexity | 40704fc29754e72178dc1186bb1c3cd7 MD5 | raw file
  1. <?php
  2. use Carbon\Carbon as Carbon;
  3. use Illuminate\Database\Seeder;
  4. use Illuminate\Support\Facades\DB;
  5. /**
  6. * Class UserTableSeeder
  7. */
  8. class UserTableSeeder extends Seeder
  9. {
  10. public function run()
  11. {
  12. if (env('DB_CONNECTION') == 'mysql') {
  13. DB::statement('SET FOREIGN_KEY_CHECKS=0;');
  14. }
  15. if (env('DB_CONNECTION') == 'mysql') {
  16. DB::table(config('access.users_table'))->truncate();
  17. } elseif (env('DB_CONNECTION') == 'sqlite') {
  18. DB::statement('DELETE FROM ' . config('access.users_table'));
  19. } else {
  20. //For PostgreSQL or anything else
  21. DB::statement('TRUNCATE TABLE ' . config('access.users_table') . ' CASCADE');
  22. }
  23. //Add the master administrator, user id of 1
  24. $users = [
  25. [
  26. 'name' => 'Admin',
  27. 'email' => 'info@webdevelopmentpark.com',
  28. 'password' => bcrypt('123456'),
  29. 'confirmation_code' => md5(uniqid(mt_rand(), true)),
  30. 'confirmed' => true,
  31. 'created_at' => Carbon::now(),
  32. 'updated_at' => Carbon::now(),
  33. ],
  34. [
  35. 'name' => 'Anil Jain',
  36. 'email' => 'aniljmk@gmail.com',
  37. 'password' => bcrypt('123456'),
  38. 'confirmation_code' => md5(uniqid(mt_rand(), true)),
  39. 'confirmed' => true,
  40. 'created_at' => Carbon::now(),
  41. 'updated_at' => Carbon::now(),
  42. ],
  43. ];
  44. DB::table(config('access.users_table'))->insert($users);
  45. if (env('DB_CONNECTION') == 'mysql') {
  46. DB::statement('SET FOREIGN_KEY_CHECKS=1;');
  47. }
  48. }
  49. }