File manager - Edit - /var/www/ratemypay_dev/database/seeders/JobExperienceSeeder.php
Back
<?php namespace Database\Seeders; use App\Models\JobExperience; use App\Models\User; use Illuminate\Database\Seeder; class JobExperienceSeeder extends Seeder { public function run() { // Fetch only users that have not added any job experience $usersWithoutJobs = User::whereDoesntHave('jobExperiences')->get(); if ($usersWithoutJobs->isEmpty()) { $this->command->info('No users without job experiences found. Skipping job experience seeding.'); return; } $this->command->info("Found {$usersWithoutJobs->count()} users without job experiences. Seeding job experiences..."); foreach ($usersWithoutJobs as $user) { // Create 1-3 job experiences per user $jobCount = rand(1, 3); for ($i = 0; $i < $jobCount; $i++) { $isCurrent = $i === 0; $employmentYear = now()->subYears(rand(1, 10))->year; $endYear = $isCurrent ? null : now()->subYears(rand(0, 5))->year; $jobExperience = JobExperience::create([ 'user_id' => $user->id, 'job_title' => $this->getJobTitle(), 'company_name' => $this->getCompanyName(), 'level' => $this->getLevel(), 'work_status' => $isCurrent ? 'current_employee' : 'former_employee', 'still_employed' => $isCurrent, 'employment_month' => rand(1, 12), 'employment_year' => $employmentYear, 'number_of_years_as_employee' => $this->calculateYearsAsEmployee($employmentYear, $endYear, $isCurrent), 'years_of_experience' => $this->calculateYearsOfExperience($user, $employmentYear), 'years_in_level' => rand(5, 30) / 10, 'location' => $this->getLocation(), 'city' => $this->getCity(), 'state' => $this->getState(), 'country' => 'Nigeria', 'work_arrangement' => $this->getWorkArrangement(), 'employment_type' => $this->getEmploymentType(), 'annual_base_salary' => $this->generateSalaryBasedOnLevel(), 'bonus_commission' => rand(0, 50000), 'overtime_pay' => rand(0, 20000), 'equity' => rand(0, 10000), 'currency' => 'NGN', 'benefits' => $this->getBenefits(), 'is_published' => $isCurrent && rand(0, 1), 'published_at' => $isCurrent && rand(0, 1) ? now() : null, 'job_description' => $this->generateJobDescription(), 'industry' => $this->getIndustry(), 'company_size' => $this->getCompanySize(), ]); $this->command->info("Created job experience for user: {$user->name} - {$jobExperience->job_title} at {$jobExperience->company_name}"); } } $this->command->info('Job experiences seeded successfully!'); } private function calculateYearsAsEmployee(int $startYear, ?int $endYear, bool $isCurrent): float { $end = $isCurrent ? now()->year : $endYear; $years = $end - $startYear; return max(0.1, $years + (rand(0, 11) / 12)); // Add random months } private function calculateYearsOfExperience(User $user, int $currentJobStartYear): float { // For new users, base on their registration date or random $baseYear = $user->created_at->year; $experience = $currentJobStartYear - $baseYear; return max(1.0, $experience + (rand(0, 11) / 12)); } private function getJobTitle(): string { $titles = [ 'Software Engineer', 'Senior Developer', 'Product Manager', 'Data Analyst', 'DevOps Engineer', 'UX Designer', 'Backend Developer', 'Frontend Developer', 'Full Stack Developer', 'Technical Lead', 'Engineering Manager', 'CTO', 'Sales Manager', 'Marketing Specialist', 'HR Coordinator', 'Financial Analyst', 'Operations Manager', 'Customer Support' ]; return $titles[array_rand($titles)]; } private function getCompanyName(): string { $companies = [ 'Tech Corp Inc.', 'Digital Solutions LLC', 'Innovation Labs', 'Data Systems Ltd', 'Cloud Services Co', 'Web Technologies Inc', 'Mobile First Ltd', 'AI Innovations', 'Blockchain Solutions', 'Global Enterprises', 'Startup Ventures', 'Corporate Solutions' ]; return $companies[array_rand($companies)]; } private function getLevel(): string { $levels = ['Junior', 'Mid-level', 'Senior', 'Lead', 'Principal', 'Manager', 'Director']; return $levels[array_rand($levels)]; } private function generateSalaryBasedOnLevel(): int { $levelSalaries = [ 'Junior' => [30000, 80000], 'Mid-level' => [80000, 150000], 'Senior' => [120000, 250000], 'Lead' => [150000, 350000], 'Principal' => [200000, 450000], 'Manager' => [180000, 400000], 'Director' => [250000, 600000], ]; $level = $this->getLevel(); $range = $levelSalaries[$level] ?? [50000, 150000]; return rand($range[0], $range[1]); } private function getLocation(): string { $locations = ['Lagos', 'Abuja', 'Port Harcourt', 'Ibadan', 'Kano', 'Remote']; return $locations[array_rand($locations)]; } private function getCity(): string { $cities = ['Lagos', 'Abuja', 'Port Harcourt', 'Ibadan', 'Kano', 'Benin City', 'Enugu']; return $cities[array_rand($cities)]; } private function getState(): string { $states = ['Lagos', 'Abuja FCT', 'Rivers', 'Oyo', 'Kano', 'Edo', 'Enugu']; return $states[array_rand($states)]; } private function getWorkArrangement(): string { $arrangements = ['onsite', 'remote', 'hybrid']; return $arrangements[array_rand($arrangements)]; } private function getEmploymentType(): string { $types = ['full_time', 'part_time', 'contract', 'freelance']; return $types[array_rand($types)]; } private function getBenefits(): string { $allBenefits = [ 'Health Insurance', 'Dental Insurance', 'Vision Insurance', 'Pension Plan', 'Paid Time Off', 'Flexible Spending Account', 'Life Insurance', 'Disability Insurance', 'Professional Development', 'Remote Work', 'Gym Membership', 'Stock Options', 'Bonus Scheme', 'Car Allowance', 'Housing Allowance', 'Childcare Support', 'Meal Vouchers', 'Transportation Allowance' ]; $numberOfBenefits = rand(3, 8); $selectedBenefits = array_rand($allBenefits, $numberOfBenefits); if (!is_array($selectedBenefits)) { $selectedBenefits = [$selectedBenefits]; } $benefitsArray = array_map(function($index) use ($allBenefits) { return $allBenefits[$index]; }, $selectedBenefits); // Convert array to comma-separated string return implode(', ', $benefitsArray); } private function generateJobDescription(): string { $descriptions = [ 'Responsible for developing and maintaining software applications, collaborating with cross-functional teams, and ensuring code quality through testing and code reviews.', 'Managed product development lifecycle from conception to launch, working closely with engineering, design, and marketing teams to deliver successful products.', 'Analyzed complex datasets to provide insights and recommendations for business decisions, created reports and dashboards for stakeholders.', 'Led a team of developers in building scalable applications, implemented best practices for code quality and deployment processes.', 'Designed user interfaces and experiences for web and mobile applications, conducted user research and testing to improve usability.', 'Managed cloud infrastructure and deployment pipelines, implemented monitoring and alerting systems for application performance.', 'Coordinated customer support operations, trained team members, and improved customer satisfaction through process optimization.', 'Developed financial models and analysis to support strategic planning, prepared reports for executive leadership.', ]; return $descriptions[array_rand($descriptions)]; } private function getIndustry(): string { $industries = [ 'Technology', 'Finance', 'Healthcare', 'Education', 'E-commerce', 'Entertainment', 'Manufacturing', 'Consulting', 'Telecommunications', 'Real Estate', 'Transportation', 'Energy', 'Design', 'Product', 'Remote', ]; return $industries[array_rand($industries)]; } private function getCompanySize(): string { $sizes = ['1-10', '11-50', '51-200', '201-500', '501-1000', '1000+']; return $sizes[array_rand($sizes)]; } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.30 | Generation time: 0.16 |
proxy
|
phpinfo
|
Settings