Feat: add database seeders for all models
This commit is contained in:
72
database/seeders/BooksPublishedTableSeeder.php
Normal file
72
database/seeders/BooksPublishedTableSeeder.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use App\Models\BooksPublished;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class BooksPublishedTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$authors = [
|
||||||
|
'Dr. A. P. J. Abdul Kalam',
|
||||||
|
'Chetan Bhagat',
|
||||||
|
'Arundhati Roy',
|
||||||
|
'Ravinder Singh',
|
||||||
|
'Kiran Desai',
|
||||||
|
'Jhumpa Lahiri',
|
||||||
|
'Ruskin Bond'
|
||||||
|
];
|
||||||
|
$titles = [
|
||||||
|
'Wings of Fire',
|
||||||
|
'Half Girlfriend',
|
||||||
|
'The God of Small Things',
|
||||||
|
'I Too Had a Love Story',
|
||||||
|
'The Inheritance of Loss',
|
||||||
|
'The Namesake',
|
||||||
|
'The Blue Umbrella'
|
||||||
|
];
|
||||||
|
$publishers = [
|
||||||
|
'Penguin Random House',
|
||||||
|
'HarperCollins',
|
||||||
|
'Rupa Publications',
|
||||||
|
'Scholastic India',
|
||||||
|
'Bloomsbury Publishing'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Number of records to seed
|
||||||
|
$numberOfRecords = 10;
|
||||||
|
|
||||||
|
for ($i = 1; $i <= $numberOfRecords; $i++) {
|
||||||
|
BooksPublished::create([
|
||||||
|
'faculty_id' => rand(1, 5),
|
||||||
|
'department_id' => rand(1, 5),
|
||||||
|
'author' => $authors[array_rand($authors)],
|
||||||
|
'title' => $titles[array_rand($titles)],
|
||||||
|
'publisher' => $publishers[array_rand($publishers)],
|
||||||
|
'issn' => rand(0, 1) ? $this->generateISSN() : null,
|
||||||
|
'date_of_publication' => Carbon::now()->subYears(rand(0, 10))->subMonths(rand(0, 12))->subDays(rand(0, 30))->format('Y-m-d'),
|
||||||
|
'proof' => null, // No proof uploaded
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateISSN()
|
||||||
|
{
|
||||||
|
$firstPart = str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT);
|
||||||
|
$secondPart = str_pad(rand(0, 999), 3, '0', STR_PAD_LEFT);
|
||||||
|
$checkDigit = rand(0, 9);
|
||||||
|
// Randomly replace the last digit with 'X'
|
||||||
|
if (rand(0, 1)) {
|
||||||
|
$checkDigit = 'X';
|
||||||
|
}
|
||||||
|
return "{$firstPart}-{$secondPart}{$checkDigit}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,10 @@ class DatabaseSeeder extends Seeder
|
|||||||
ActivitiesOrganisedTableSeeder::class,
|
ActivitiesOrganisedTableSeeder::class,
|
||||||
IvOrganisedTableSeeder::class,
|
IvOrganisedTableSeeder::class,
|
||||||
PublicationSeeder::class,
|
PublicationSeeder::class,
|
||||||
|
BooksPublishedTableSeeder::class,
|
||||||
|
PatentsTableSeeder::class,
|
||||||
|
ExternalEngagementsTableSeeder::class,
|
||||||
|
OnlineCoursesTableSeeder::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// User::factory()->create([
|
// User::factory()->create([
|
||||||
|
|||||||
@@ -2,21 +2,19 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use App\Models\Department;
|
||||||
|
|
||||||
class DepartmentSeeder extends Seeder
|
class DepartmentSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
public function run()
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
|
||||||
{
|
{
|
||||||
DB::table('roles')->insert([
|
Department::insert([
|
||||||
['name' => 'Admin'],
|
['name' => 'Computer Science'],
|
||||||
['name' => 'Coordinator'],
|
['name' => 'Mechanical Engineering'],
|
||||||
['name' => 'Faculty'],
|
['name' => 'Electrical Engineering'],
|
||||||
|
['name' => 'Civil Engineering'],
|
||||||
|
['name' => 'Information Technology']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
database/seeders/ExternalEngagementsTableSeeder.php
Normal file
70
database/seeders/ExternalEngagementsTableSeeder.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use App\Models\ExternalEngagement;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class ExternalEngagementsTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$activities = [
|
||||||
|
'Guest Lecture',
|
||||||
|
'Workshop Facilitator',
|
||||||
|
'Conference Speaker',
|
||||||
|
'Panel Discussion Member',
|
||||||
|
'Industry Training Program',
|
||||||
|
'Research Collaboration Meet',
|
||||||
|
'Technical Seminar'
|
||||||
|
];
|
||||||
|
|
||||||
|
$activityDescriptions = [
|
||||||
|
'Conducted an advanced session on emerging AI trends.',
|
||||||
|
'Facilitated a two-day workshop on cybersecurity practices.',
|
||||||
|
'Spoke on innovations in renewable energy.',
|
||||||
|
'Participated in a panel discussion on education reform.',
|
||||||
|
'Provided industrial training on IoT devices.',
|
||||||
|
'Collaborated on a research project in machine learning.',
|
||||||
|
'Delivered a seminar on blockchain technology.'
|
||||||
|
];
|
||||||
|
|
||||||
|
$invitingOrganizations = [
|
||||||
|
'Indian Institute of Technology',
|
||||||
|
'National Institute of Technology',
|
||||||
|
'Infosys Ltd.',
|
||||||
|
'Tata Consultancy Services',
|
||||||
|
'Microsoft Research',
|
||||||
|
'ISRO',
|
||||||
|
'Bharat Electronics Limited'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Number of records to seed
|
||||||
|
$numberOfRecords = 10;
|
||||||
|
|
||||||
|
for ($i = 1; $i <= $numberOfRecords; $i++) {
|
||||||
|
// Generate random start and end dates
|
||||||
|
$startDate = Carbon::now()->subMonths(rand(1, 24))->subDays(rand(0, 30));
|
||||||
|
$endDate = (clone $startDate)->addDays(rand(1, 5)); // 1 to 5 days later
|
||||||
|
$numDays = $startDate->diffInDays($endDate) + 1; // Including start day
|
||||||
|
|
||||||
|
ExternalEngagement::create([
|
||||||
|
'faculty_id' => rand(1, 5),
|
||||||
|
'department_id' => rand(1, 5),
|
||||||
|
'activity' => $activities[array_rand($activities)],
|
||||||
|
'activity_description' => $activityDescriptions[array_rand($activityDescriptions)],
|
||||||
|
'inviting_organization' => $invitingOrganizations[array_rand($invitingOrganizations)],
|
||||||
|
'start_date' => $startDate->format('Y-m-d'),
|
||||||
|
'end_date' => $endDate->format('Y-m-d'),
|
||||||
|
'num_days' => $numDays,
|
||||||
|
'proof' => null, // Proof left null for now
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
59
database/seeders/OnlineCoursesTableSeeder.php
Normal file
59
database/seeders/OnlineCoursesTableSeeder.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use App\Models\OnlineCourse;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class OnlineCoursesTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$courses = [
|
||||||
|
'Machine Learning Fundamentals',
|
||||||
|
'Blockchain Basics',
|
||||||
|
'Introduction to Cybersecurity',
|
||||||
|
'Cloud Computing Essentials',
|
||||||
|
'Artificial Intelligence for Everyone',
|
||||||
|
'Internet of Things (IoT) Applications',
|
||||||
|
'Big Data Analytics'
|
||||||
|
];
|
||||||
|
|
||||||
|
$offeredBys = [
|
||||||
|
'Coursera',
|
||||||
|
'edX',
|
||||||
|
'Udemy',
|
||||||
|
'NPTEL',
|
||||||
|
'Google Digital Garage',
|
||||||
|
'LinkedIn Learning',
|
||||||
|
'Microsoft Learn'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Number of records to seed
|
||||||
|
$numberOfRecords = 10;
|
||||||
|
|
||||||
|
for ($i = 1; $i <= $numberOfRecords; $i++) {
|
||||||
|
// Generate random start and end dates
|
||||||
|
$startDate = Carbon::now()->subMonths(rand(1, 12))->subDays(rand(0, 30));
|
||||||
|
$endDate = (clone $startDate)->addDays(rand(5, 90)); // Course duration between 5 to 90 days
|
||||||
|
$numDays = $startDate->diffInDays($endDate) + 1;
|
||||||
|
|
||||||
|
OnlineCourse::create([
|
||||||
|
'faculty_id' => rand(1, 5),
|
||||||
|
'department_id' => rand(1, 5),
|
||||||
|
'course' => $courses[array_rand($courses)],
|
||||||
|
'offered_by' => $offeredBys[array_rand($offeredBys)],
|
||||||
|
'start_date' => $startDate->format('Y-m-d'),
|
||||||
|
'end_date' => $endDate->format('Y-m-d'),
|
||||||
|
'num_days' => $numDays,
|
||||||
|
'proof' => null, // Proof left null
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
62
database/seeders/PatentsTableSeeder.php
Normal file
62
database/seeders/PatentsTableSeeder.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use App\Models\Patent;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
|
class PatentsTableSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$titles = [
|
||||||
|
'Smart Irrigation System',
|
||||||
|
'AI-Based Traffic Control',
|
||||||
|
'Wearable Health Monitoring Device',
|
||||||
|
'Solar-Powered Water Purifier',
|
||||||
|
'Autonomous Drone Navigation System',
|
||||||
|
'Blockchain-based Voting System',
|
||||||
|
'Biodegradable Packaging Material'
|
||||||
|
];
|
||||||
|
|
||||||
|
$investigators = [
|
||||||
|
'Dr. Anjali Verma',
|
||||||
|
'Prof. Ravi Kumar',
|
||||||
|
'Dr. Meera Iyer',
|
||||||
|
'Dr. Arjun Singh',
|
||||||
|
'Prof. Sneha Shah',
|
||||||
|
'Dr. Vikrant Joshi'
|
||||||
|
];
|
||||||
|
|
||||||
|
$types = ['Provisional', 'Complete', 'Design', 'Innovation Patent'];
|
||||||
|
$statuses = ['Filed', 'Published', 'Granted', 'Rejected'];
|
||||||
|
|
||||||
|
// Number of records to seed
|
||||||
|
$numberOfRecords = 10;
|
||||||
|
|
||||||
|
for ($i = 1; $i <= $numberOfRecords; $i++) {
|
||||||
|
// Random submission and filling dates
|
||||||
|
$submissionDate = Carbon::now()->subYears(rand(1, 5))->subMonths(rand(0, 11))->subDays(rand(0, 29));
|
||||||
|
$fillingDate = (clone $submissionDate)->addDays(rand(1, 60));
|
||||||
|
|
||||||
|
Patent::create([
|
||||||
|
'faculty_id' => rand(1, 5),
|
||||||
|
'department_id' => rand(1, 5),
|
||||||
|
'title' => $titles[array_rand($titles)],
|
||||||
|
'investigator' => $investigators[array_rand($investigators)],
|
||||||
|
'application_no' => 'APP' . rand(100000, 999999), // Random Application No
|
||||||
|
'type' => $types[array_rand($types)],
|
||||||
|
'date_of_submission' => $submissionDate->format('Y-m-d'),
|
||||||
|
'date_of_filling' => $fillingDate->format('Y-m-d'),
|
||||||
|
'status' => $statuses[array_rand($statuses)],
|
||||||
|
'proof' => null, // No proof uploaded
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,23 +2,17 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use App\Models\Role;
|
||||||
|
|
||||||
class RoleSeeder extends Seeder
|
class RoleSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
public function run()
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
|
||||||
{
|
{
|
||||||
DB::table('departments')->insert([
|
Role::insert([
|
||||||
['name' => 'Computer Engineering'],
|
['name' => 'Admin'],
|
||||||
['name' => 'Information Technology'],
|
['name' => 'Coordinator'],
|
||||||
['name' => 'Mechanical Engineering'],
|
['name' => 'Faculty']
|
||||||
['name' => 'Electrical Engineering'],
|
|
||||||
['name' => 'Civil Engineering'],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user