296 lines
10 KiB
PHP
296 lines
10 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Resume>
|
|
*/
|
|
class ResumeFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$templates = ['professional', 'modern', 'executive', 'minimal', 'technical'];
|
|
$statuses = ['draft', 'published', 'archived'];
|
|
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'title' => fake()->sentence(3),
|
|
'description' => fake()->paragraph(),
|
|
'template' => fake()->randomElement($templates),
|
|
'content' => $this->generateSampleContent(),
|
|
'settings' => $this->generateSettings(),
|
|
'status' => fake()->randomElement($statuses),
|
|
'is_public' => fake()->boolean(30), // 30% chance of being public
|
|
'public_url' => fake()->optional(0.3)->slug(),
|
|
'published_at' => fake()->optional(0.5)->dateTimeBetween('-6 months', 'now'),
|
|
'view_count' => fake()->numberBetween(0, 1000),
|
|
'download_count' => fake()->numberBetween(0, 100),
|
|
'last_viewed_at' => fake()->optional(0.7)->dateTimeBetween('-1 month', 'now'),
|
|
'last_downloaded_at' => fake()->optional(0.4)->dateTimeBetween('-1 month', 'now'),
|
|
'completion_percentage' => fake()->numberBetween(25, 100),
|
|
'completion_sections' => $this->generateCompletionSections(),
|
|
'analytics' => [
|
|
'total_views' => fake()->numberBetween(0, 1000),
|
|
'unique_visitors' => fake()->numberBetween(0, 500),
|
|
'avg_time_on_page' => fake()->numberBetween(30, 300),
|
|
'bounce_rate' => fake()->randomFloat(2, 0, 1),
|
|
],
|
|
'allow_comments' => fake()->boolean(20),
|
|
'expires_at' => fake()->optional(0.2)->dateTimeBetween('now', '+1 year'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Generate sample resume content.
|
|
*/
|
|
private function generateSampleContent(): array
|
|
{
|
|
return [
|
|
'personal_info' => [
|
|
'full_name' => fake()->name(),
|
|
'title' => fake()->jobTitle(),
|
|
'email' => fake()->email(),
|
|
'phone' => fake()->phoneNumber(),
|
|
'location' => fake()->city() . ', ' . fake()->country(),
|
|
'website' => fake()->optional()->url(),
|
|
'linkedin' => fake()->optional()->url(),
|
|
'github' => fake()->optional()->url(),
|
|
],
|
|
'summary' => fake()->paragraph(4),
|
|
'experience' => $this->generateExperience(),
|
|
'education' => $this->generateEducation(),
|
|
'skills' => $this->generateSkills(),
|
|
'projects' => fake()->optional(0.7)->passthrough($this->generateProjects()),
|
|
'certifications' => fake()->optional(0.5)->passthrough($this->generateCertifications()),
|
|
'languages' => fake()->optional(0.6)->passthrough($this->generateLanguages()),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Generate work experience.
|
|
*/
|
|
private function generateExperience(): array
|
|
{
|
|
$experiences = [];
|
|
$count = fake()->numberBetween(1, 4);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$startDate = fake()->dateTimeBetween('-10 years', '-1 year');
|
|
$isCurrent = $i === 0 && fake()->boolean(40);
|
|
|
|
$experiences[] = [
|
|
'company' => fake()->company(),
|
|
'position' => fake()->jobTitle(),
|
|
'location' => fake()->city() . ', ' . fake()->country(),
|
|
'start_date' => $startDate->format('Y-m-d'),
|
|
'end_date' => $isCurrent ? null : fake()->dateTimeBetween($startDate, 'now')->format('Y-m-d'),
|
|
'current' => $isCurrent,
|
|
'description' => fake()->paragraph(2),
|
|
'achievements' => fake()->sentences(fake()->numberBetween(2, 5)),
|
|
];
|
|
}
|
|
|
|
return $experiences;
|
|
}
|
|
|
|
/**
|
|
* Generate education.
|
|
*/
|
|
private function generateEducation(): array
|
|
{
|
|
$education = [];
|
|
$count = fake()->numberBetween(1, 3);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$startDate = fake()->dateTimeBetween('-15 years', '-2 years');
|
|
$endDate = fake()->dateTimeBetween($startDate, '-1 year');
|
|
|
|
$education[] = [
|
|
'institution' => fake()->company() . ' University',
|
|
'degree' => fake()->randomElement(['Bachelor of Science', 'Master of Science', 'Bachelor of Arts', 'Master of Arts']),
|
|
'field' => fake()->randomElement(['Computer Science', 'Information Technology', 'Software Engineering', 'Business Administration']),
|
|
'start_date' => $startDate->format('Y-m-d'),
|
|
'end_date' => $endDate->format('Y-m-d'),
|
|
'gpa' => fake()->optional(0.7)->randomFloat(1, 2.5, 4.0),
|
|
'description' => fake()->optional(0.5)->sentence(),
|
|
];
|
|
}
|
|
|
|
return $education;
|
|
}
|
|
|
|
/**
|
|
* Generate skills.
|
|
*/
|
|
private function generateSkills(): array
|
|
{
|
|
$skillCategories = [
|
|
'Programming Languages' => ['PHP', 'JavaScript', 'Python', 'Java', 'TypeScript'],
|
|
'Frontend' => ['React', 'Angular', 'Vue.js', 'HTML5', 'CSS3', 'Bootstrap'],
|
|
'Backend' => ['Laravel', 'Node.js', 'Express', 'Django', 'Spring Boot'],
|
|
'Databases' => ['MySQL', 'PostgreSQL', 'MongoDB', 'Redis'],
|
|
'Tools & Technologies' => ['Git', 'Docker', 'AWS', 'Linux', 'Jenkins'],
|
|
];
|
|
|
|
$skills = [];
|
|
$numCategories = fake()->numberBetween(2, 5);
|
|
$categories = fake()->randomElements(array_keys($skillCategories), $numCategories);
|
|
|
|
foreach ($categories as $category) {
|
|
$skills[$category] = fake()->randomElements($skillCategories[$category], fake()->numberBetween(2, 4));
|
|
}
|
|
|
|
return $skills;
|
|
}
|
|
|
|
/**
|
|
* Generate projects.
|
|
*/
|
|
private function generateProjects(): array
|
|
{
|
|
$projects = [];
|
|
$count = fake()->numberBetween(1, 4);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$projects[] = [
|
|
'name' => fake()->catchPhrase(),
|
|
'description' => fake()->paragraph(),
|
|
'technologies' => fake()->randomElements(['Laravel', 'React', 'Vue.js', 'MySQL', 'Docker', 'AWS'], fake()->numberBetween(2, 4)),
|
|
'url' => fake()->optional(0.6)->url(),
|
|
'achievements' => fake()->sentences(fake()->numberBetween(2, 4)),
|
|
];
|
|
}
|
|
|
|
return $projects;
|
|
}
|
|
|
|
/**
|
|
* Generate certifications.
|
|
*/
|
|
private function generateCertifications(): array
|
|
{
|
|
$certifications = [];
|
|
$count = fake()->numberBetween(1, 3);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
$certifications[] = [
|
|
'name' => fake()->sentence(4),
|
|
'issuer' => fake()->company(),
|
|
'date' => fake()->dateTimeBetween('-5 years', 'now')->format('Y-m-d'),
|
|
'credential_id' => fake()->optional(0.7)->bothify('??###-####'),
|
|
'url' => fake()->optional(0.5)->url(),
|
|
];
|
|
}
|
|
|
|
return $certifications;
|
|
}
|
|
|
|
/**
|
|
* Generate languages.
|
|
*/
|
|
private function generateLanguages(): array
|
|
{
|
|
$languages = ['English', 'Spanish', 'French', 'German', 'Italian', 'Portuguese', 'Chinese', 'Japanese'];
|
|
$levels = ['Native', 'Fluent', 'Advanced', 'Intermediate', 'Basic'];
|
|
|
|
$result = [];
|
|
$count = fake()->numberBetween(1, 4);
|
|
$selectedLanguages = fake()->randomElements($languages, $count);
|
|
|
|
foreach ($selectedLanguages as $language) {
|
|
$result[] = [
|
|
'language' => $language,
|
|
'level' => fake()->randomElement($levels),
|
|
];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Generate settings.
|
|
*/
|
|
private function generateSettings(): array
|
|
{
|
|
return [
|
|
'color_scheme' => fake()->randomElement(['blue', 'green', 'red', 'purple', 'orange']),
|
|
'font_family' => fake()->randomElement(['Arial', 'Times New Roman', 'Calibri', 'Helvetica']),
|
|
'font_size' => fake()->numberBetween(9, 12),
|
|
'line_spacing' => fake()->randomFloat(1, 1.0, 1.5),
|
|
'margin' => fake()->numberBetween(15, 25),
|
|
'show_photo' => fake()->boolean(30),
|
|
'section_order' => ['summary', 'experience', 'education', 'skills', 'projects', 'certifications', 'languages'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Generate completion sections.
|
|
*/
|
|
private function generateCompletionSections(): array
|
|
{
|
|
$sections = ['personal_info', 'summary', 'experience', 'education', 'skills', 'projects', 'certifications', 'languages'];
|
|
$completed = [];
|
|
|
|
foreach ($sections as $section) {
|
|
$completed[$section] = fake()->boolean(80); // 80% chance of being completed
|
|
}
|
|
|
|
return $completed;
|
|
}
|
|
|
|
/**
|
|
* Indicate that the resume is published.
|
|
*/
|
|
public function published()
|
|
{
|
|
return $this->state(function (array $attributes) {
|
|
return [
|
|
'status' => 'published',
|
|
'published_at' => fake()->dateTimeBetween('-6 months', 'now'),
|
|
'is_public' => true,
|
|
'public_url' => fake()->slug(),
|
|
'completion_percentage' => fake()->numberBetween(80, 100),
|
|
];
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Indicate that the resume is a draft.
|
|
*/
|
|
public function draft()
|
|
{
|
|
return $this->state(function (array $attributes) {
|
|
return [
|
|
'status' => 'draft',
|
|
'published_at' => null,
|
|
'is_public' => false,
|
|
'public_url' => null,
|
|
'completion_percentage' => fake()->numberBetween(25, 75),
|
|
];
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Indicate that the resume is popular.
|
|
*/
|
|
public function popular()
|
|
{
|
|
return $this->state(function (array $attributes) {
|
|
return [
|
|
'view_count' => fake()->numberBetween(500, 5000),
|
|
'download_count' => fake()->numberBetween(50, 500),
|
|
'is_public' => true,
|
|
'status' => 'published',
|
|
];
|
|
});
|
|
}
|
|
}
|