diff --git a/app/Http/Controllers/AIAnalysisController.php b/app/Http/Controllers/AIAnalysisController.php index 1456934..6596352 100644 --- a/app/Http/Controllers/AIAnalysisController.php +++ b/app/Http/Controllers/AIAnalysisController.php @@ -23,6 +23,12 @@ class AIAnalysisController extends Controller try { $analysis = $this->aiService->analyze($candidate); + + // Persist the analysis on the candidate profile + $candidate->update([ + 'ai_analysis' => $analysis + ]); + return response()->json($analysis); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 500); diff --git a/app/Models/Candidate.php b/app/Models/Candidate.php index 894027c..2feae11 100644 --- a/app/Models/Candidate.php +++ b/app/Models/Candidate.php @@ -9,11 +9,15 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; -#[Fillable(['user_id', 'job_position_id', 'phone', 'linkedin_url', 'status', 'notes', 'cv_score', 'motivation_score', 'interview_score'])] +#[Fillable(['user_id', 'job_position_id', 'phone', 'linkedin_url', 'status', 'notes', 'cv_score', 'motivation_score', 'interview_score', 'ai_analysis'])] class Candidate extends Model { use HasFactory; + protected $casts = [ + 'ai_analysis' => 'array', + ]; + public function jobPosition(): BelongsTo { return $this->belongsTo(JobPosition::class); diff --git a/database/migrations/2026_03_22_213122_add_ai_analysis_to_candidates_table.php b/database/migrations/2026_03_22_213122_add_ai_analysis_to_candidates_table.php new file mode 100644 index 0000000..67a9a53 --- /dev/null +++ b/database/migrations/2026_03_22_213122_add_ai_analysis_to_candidates_table.php @@ -0,0 +1,28 @@ +json('ai_analysis')->nullable()->after('interview_score'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('candidates', function (Blueprint $table) { + $table->dropColumn('ai_analysis'); + }); + } +}; diff --git a/resources/js/Pages/Admin/Candidates/Show.vue b/resources/js/Pages/Admin/Candidates/Show.vue index 3907930..c233498 100644 --- a/resources/js/Pages/Admin/Candidates/Show.vue +++ b/resources/js/Pages/Admin/Candidates/Show.vue @@ -120,7 +120,7 @@ const updateAnswerScore = (answerId, score) => { }); }; -const aiAnalysis = ref(null); +const aiAnalysis = ref(props.candidate.ai_analysis || null); const isAnalyzing = ref(false); const runAI = async () => {