Build: Seeder for users and responses

This commit is contained in:
Sallu9007
2025-01-27 01:03:13 +05:30
parent 06ebafd104
commit beb4adfaef
3 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\Response;
use Carbon\Carbon;
class ResponsesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Example data for random selection
$titles = ['AI Workshop', 'Cloud Computing', 'Cybersecurity Basics', 'Data Analytics', 'Machine Learning', 'Blockchain Essentials'];
$organizingInstitutes = ['Google', 'Microsoft', 'Amazon', 'IBM', 'Oracle'];
$addresses = ['New York, USA', 'London, UK', 'Mumbai, India', 'Berlin, Germany', 'Tokyo, Japan'];
$activityTypes = ['GL', 'IC', 'STTP'];
$categories = ['Technical', 'Social', 'Entrepreneurial', 'Life Skill'];
$levels = ['College', 'State', 'National', 'International'];
// Number of responses to seed
$numberOfResponses = 10;
for ($i = 1; $i <= $numberOfResponses; $i++) {
// Generate random start and end dates
$startDate = Carbon::now()->subDays(rand(1, 30))->addHours(rand(0, 23))->addMinutes(rand(0, 59));
$endDate = (clone $startDate)->addDays(rand(0, 3))->addHours(rand(0, 23))->addMinutes(rand(0, 59));
$numDays = $startDate->diffInDays($endDate) ?: 1;
// Create the response record
Response::create([
'title' => $titles[array_rand($titles)], // Random title
'organising_institute' => $organizingInstitutes[array_rand($organizingInstitutes)], // Random organization
'address' => $addresses[array_rand($addresses)], // Random address
'department_id' => rand(1, 5), // Random department ID
'faculty_id' => rand(1, 3), // Random faculty ID
'start_date' => $startDate->format('Y-m-d H:i:s'), // Start date and time
'end_date' => $endDate->format('Y-m-d H:i:s'), // End date and time
'num_days' => $numDays, // Number of days
'activity_type' => $activityTypes[array_rand($activityTypes)], // Random activity type
'category' => $categories[array_rand($categories)], // Random category
'level' => $levels[array_rand($levels)], // Random level
'proof' => null, // Null for proof
]);
}
}
}