Skip to content

Commit

Permalink
car table seed
Browse files Browse the repository at this point in the history
  • Loading branch information
stazrouti committed Sep 16, 2024
1 parent d8ded29 commit cae81f2
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions rental-car-backend/database/seeders/CarSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@
use Illuminate\Support\Facades\DB;
use Faker\Factory as Faker;
use Carbon\Carbon;
use App\Models\Car;

class CarSeeder extends Seeder
{
public function run()
public function run(): void
{
// Create a Faker instance
$faker = Faker::create();

foreach (range(1, 50) as $index) {
DB::table('cars')->insert([
'Name' => $faker->company,
'Model' => $faker->word,
'Year' => $faker->year,
'Doors' => $faker->numberBetween(2, 5),
'AC' => $faker->boolean ? 'Yes' : 'No',
'Transmission' => $faker->randomElement(['Manual', 'Automatic']),
'Fuel' => $faker->randomElement(['Petrol', 'Diesel', 'Electric']),
'Price_per_day' => $faker->randomFloat(2, 10, 200),
'Status' => $faker->randomElement(['Available', 'Rented', 'Maintenance']),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
// Seed 20 cars with random data
for ($i = 0; $i < 20; $i++) {
Car::create([
'Name' => $faker->company, // Random car make, e.g., Toyota, Ford
'Model' => $faker->word, // Random car model, e.g., Corolla, Focus
'Year' => $faker->year, // Random year of manufacture
'Doors' => $faker->randomElement([2, 4]), // Random number of doors (2 or 4)
'AC' => $faker->randomElement(['Yes', 'No']), // Random AC availability
'Transmission' => $faker->randomElement(['Manual', 'Automatic']), // Random transmission type
'Fuel' => $faker->randomElement(['Petrol', 'Diesel', 'Electric']), // Random fuel type
'Price_per_day' => $faker->randomFloat(2, 50, 300), // Random rental price per day (50 to 300)
'Status' => $faker->randomElement(['Available', 'Rented', 'Maintenance']), // Random status
'created_at' => now(),
'updated_at' => now(),
]);
}
}
Expand Down

0 comments on commit cae81f2

Please sign in to comment.