<?php
use Illuminate\Database\Seeder;
// Import DB and Faker services
use Illuminate\Support\Facades\DB;
use Faker\Factory as Faker;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$faker = Faker::create();
foreach (range(1, 500) as $index) {
DB::table('employees')->insert([
'firstname' => $faker->firstname,
'lastname' => $faker->lastname,
'email' => $faker->email,
'dob' => $faker->date($format = 'D-m-y', $max = '2010', $min = '1980')
]);
}
}
}
C:\xampp\htdocs\datvietcoconut\database\migrations\2022_12_09_185509_create_employees_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEmployeesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('employees', function (Blueprint $table) {
$table->id();
$table->string('firstname');
$table->string('lastname');
$table->string('email')->unique();
$table->string('dob');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('employees');
}
}
Route::get('/convert-to-json', function () {
return Employee::paginate(5);
});