Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use IlluminateDatabaseSeeder;
- class UsersTableSeeder extends Seeder
- {
- /**
- * Run the database seeds.
- *
- * @return void
- */
- public function run()
- {
- factory('AppUser', 50)->create();
- }
- }
- use IlluminateDatabaseSeeder;
- class DatabaseSeeder extends Seeder
- {
- protected $toTruncate = ['users'];
- public function run()
- {
- foreach ($this-> $toTruncate as $table)
- {
- DB::table('users')->truncate();
- }
- $this->call(UsersTableSeeder::class);
- }
- }
- <?php
- /*
- |--------------------------------------------------------------------------
- | Model Factories
- |--------------------------------------------------------------------------
- |
- | Here you may define all of your model factories. Model factories give
- | you a convenient way to create models for testing and seeding your
- | database. Just tell the factory how a default model should look.
- |
- */
- /** @var IlluminateDatabaseEloquentFactory $factory */
- $factory->define(AppUser::class, function (FakerGenerator $faker) {
- static $password;
- return [
- 'name' => $faker->name,
- 'email' => $faker->unique()->safeEmail,
- 'body' => $faker->sentences(),
- 'password' => $password ?: $password = bcrypt('secret'),
- 'remember_token' => str_random(10),
- ];
- });
- <?php
- use IlluminateSupportFacadesSchema;
- use IlluminateDatabaseSchemaBlueprint;
- use IlluminateDatabaseMigrationsMigration;
- class CreateUsersTable extends Migration
- {
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('users', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name');
- $table->string('email')->unique();
- $table->text('body');
- $table->string('password');
- $table->rememberToken();
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('users');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement