/** * Run the database seeds. * * @return void */ public function run() { $ut = array(['name' => 'Student'], ['name' => 'Staff'], ['name' => 'Parent'], ['name' => 'Foundation'], ['name' => 'SuperAdmin']); foreach ($ut as $index => $userType) { App\Models\UserType::create($userType); } }
/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); DB::table('users')->delete(); DB::table('usertypes')->delete(); $adminType = new \App\Models\UserType(); $adminType->name = "ADMIN"; $adminType->description = "Admin Type"; $alumniType = new \App\Models\UserType(); $alumniType->name = "ALUMNI"; $alumniType->description = "Alumni User Type"; $adminType->save(); $alumniType->save(); $adminUser = new \App\Models\User(); $adminUser->username = "******"; $adminUser->password = bcrypt('admin'); $adminUser->national_id = "0000000000000"; $adminUser->birthdate = \Carbon\Carbon::createFromDate(2000, 1, 1)->toDateString(); $adminUser->email = "*****@*****.**"; $adminUser->firstname = "ชลติพันธ์"; $adminUser->lastname = "เปล่งวิทยา"; $adminType->users()->save($adminUser); Model::reguard(); }
<?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. | */ $factory->define(App\Models\User::class, function ($faker) { return ['name' => $faker->name, 'email' => $faker->email, 'username' => str_random(10), 'password' => bcrypt(1234), 'date_of_birth' => $faker->date, 'phone' => $faker->numberBetween(9000, 9999) . $faker->numberBetween(00, 999999), 'gender' => ['M', 'F'][array_rand(['M', 'F'])], 'address' => $faker->address, 'avatar' => $faker->imageUrl(300, 300, 'people', true, 'Faker'), 'user_type_id' => App\Models\UserType::all()->random()->id, 'school_id' => App\Models\School::all(['id'])->random()->id, 'status' => ['ACTIVE', 'WAITING_APPROVAL', 'BLOCKED'][array_rand(['ACTIVE', 'WAITING_APPROVAL', 'BLOCKED'])], 'remember_token' => str_random(10)]; }); $factory->define(App\Models\Message::class, function ($faker) { return ['sender_id' => App\Models\User::all()->random()->id, 'receiver_id' => App\Models\User::all()->random()->id, 'message' => $faker->paragraph, 'is_read' => ['', '1'][array_rand(['', '1'])]]; }); $factory->define(App\Models\RelatedUser::class, function ($faker) { return ['user_id' => App\Models\User::all()->random()->id, 'related_id' => App\Models\User::all()->random()->id, 'status' => ['ALLOW', 'DENY', 'NOT_YET_ALLOWED'][array_rand(['APPROVED', 'DENIED', 'NOT_YET_ALLOWED'])]]; }); $factory->define(App\Models\CourseSchool::class, function ($faker) { return ['course_id' => App\Models\Course::all()->random()->id, 'school_id' => App\Models\School::all()->random()->id]; }); $factory->define(App\Models\Student::class, function ($faker) { $user = factory('App\\Models\\User')->make(); $user->user_type_id = 1; $user->username = '******' . (App\Models\User::count() + 1); $user->save(); return ['course_school_id' => App\Models\CourseSchool::all()->random()->id, 'roll_no' => $faker->numberBetween(1, 60), 'admission_no' => $faker->numberBetween(100, 9999), 'year_of_admission' => $faker->year, 'user_id' => $user->id]; });