'required|string|max:255', 'category' => 'required|string|max:255', 'proficiency_level' => 'required|integer|min:1|max:5', 'certification_body' => 'nullable|string|max:255', 'certification_expires' => 'nullable|date', 'is_primary_skill' => 'boolean', 'notes' => 'nullable|string|max:1000' ]; #[On('manage-skills')] public function manageSkills($technicianId) { $this->technicianId = $technicianId; $this->technician = Technician::with('skills')->findOrFail($technicianId); $this->showModal = true; $this->resetForm(); } public function addSkill() { $this->resetForm(); $this->editing = false; } public function editSkill($skillId) { $skill = TechnicianSkill::findOrFail($skillId); $this->skillId = $skill->id; $this->skill_name = $skill->skill_name; $this->category = $skill->category; $this->proficiency_level = $skill->proficiency_level; $this->certification_body = $skill->certification_body; $this->certification_expires = $skill->certification_expires ? $skill->certification_expires->format('Y-m-d') : ''; $this->is_primary_skill = $skill->is_primary_skill; $this->notes = $skill->notes; $this->editing = true; } public function saveSkill() { $this->validate(); $data = [ 'technician_id' => $this->technicianId, 'skill_name' => $this->skill_name, 'category' => $this->category, 'proficiency_level' => $this->proficiency_level, 'certification_body' => $this->certification_body, 'certification_expires' => $this->certification_expires ?: null, 'is_primary_skill' => $this->is_primary_skill, 'notes' => $this->notes, ]; if ($this->editing) { $skill = TechnicianSkill::findOrFail($this->skillId); $skill->update($data); session()->flash('message', 'Skill updated successfully!'); } else { TechnicianSkill::create($data); session()->flash('message', 'Skill added successfully!'); } $this->technician->refresh(); $this->resetForm(); } public function deleteSkill($skillId) { TechnicianSkill::findOrFail($skillId)->delete(); $this->technician->refresh(); session()->flash('message', 'Skill removed successfully!'); } public function closeModal() { $this->showModal = false; $this->resetForm(); } public function resetForm() { $this->skillId = null; $this->skill_name = ''; $this->category = ''; $this->proficiency_level = 1; $this->certification_body = ''; $this->certification_expires = ''; $this->is_primary_skill = false; $this->notes = ''; $this->editing = false; $this->resetErrorBag(); } public function getSkillCategoriesProperty() { return TechnicianSkill::getSkillCategories(); } public function getCommonSkillsProperty() { return TechnicianSkill::getCommonSkills(); } public function getProficiencyLevelsProperty() { return TechnicianSkill::getProficiencyLevels(); } public function render() { return view('livewire.technician-management.skills-management', [ 'skillCategories' => $this->skillCategories, 'commonSkills' => $this->commonSkills, 'proficiencyLevels' => $this->proficiencyLevels ]); } }