Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <?php
  2.  
  3. use IlluminateDatabaseSeeder;
  4.  
  5. class UsersTableSeeder extends Seeder
  6. {
  7. /**
  8. * Run the database seeds.
  9. *
  10. * @return void
  11. */
  12. public function run()
  13. {
  14. factory('AppUser', 50)->create();
  15. }
  16. }
  17.  
  18. use IlluminateDatabaseSeeder;
  19.  
  20. class DatabaseSeeder extends Seeder
  21. {
  22. protected $toTruncate = ['users'];
  23.  
  24. public function run()
  25. {
  26.  
  27.  
  28.  
  29. foreach ($this-> $toTruncate as $table)
  30. {
  31. DB::table('users')->truncate();
  32.  
  33.  
  34. }
  35.  
  36.  
  37. $this->call(UsersTableSeeder::class);
  38. }
  39. }
  40.  
  41. <?php
  42.  
  43. /*
  44. |--------------------------------------------------------------------------
  45. | Model Factories
  46. |--------------------------------------------------------------------------
  47. |
  48. | Here you may define all of your model factories. Model factories give
  49. | you a convenient way to create models for testing and seeding your
  50. | database. Just tell the factory how a default model should look.
  51. |
  52. */
  53.  
  54. /** @var IlluminateDatabaseEloquentFactory $factory */
  55. $factory->define(AppUser::class, function (FakerGenerator $faker) {
  56. static $password;
  57.  
  58. return [
  59. 'name' => $faker->name,
  60. 'email' => $faker->unique()->safeEmail,
  61. 'body' => $faker->sentences(),
  62. 'password' => $password ?: $password = bcrypt('secret'),
  63. 'remember_token' => str_random(10),
  64. ];
  65. });
  66.  
  67. <?php
  68.  
  69. use IlluminateSupportFacadesSchema;
  70. use IlluminateDatabaseSchemaBlueprint;
  71. use IlluminateDatabaseMigrationsMigration;
  72.  
  73. class CreateUsersTable extends Migration
  74. {
  75. /**
  76. * Run the migrations.
  77. *
  78. * @return void
  79. */
  80. public function up()
  81. {
  82. Schema::create('users', function (Blueprint $table) {
  83. $table->increments('id');
  84. $table->string('name');
  85. $table->string('email')->unique();
  86. $table->text('body');
  87. $table->string('password');
  88. $table->rememberToken();
  89. $table->timestamps();
  90. });
  91. }
  92.  
  93. /**
  94. * Reverse the migrations.
  95. *
  96. * @return void
  97. */
  98. public function down()
  99. {
  100. Schema::dropIfExists('users');
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement