From 38fe4a22d6051f1d532d2093de0e3a276df6d0b5 Mon Sep 17 00:00:00 2001 From: jeremy bayse Date: Sun, 29 Mar 2026 11:25:53 +0200 Subject: [PATCH] feat: automatic tenant_id sync for candidates from job position --- app/Models/Candidate.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Models/Candidate.php b/app/Models/Candidate.php index 8189614..848ad4a 100644 --- a/app/Models/Candidate.php +++ b/app/Models/Candidate.php @@ -15,6 +15,18 @@ use App\Traits\BelongsToTenant; class Candidate extends Model { use HasFactory, BelongsToTenant; + + protected static function booted() + { + static::creating(function ($candidate) { + if ($candidate->job_position_id && !$candidate->tenant_id) { + $jobPosition = JobPosition::find($candidate->job_position_id); + if ($jobPosition) { + $candidate->tenant_id = $jobPosition->tenant_id; + } + } + }); + } protected $casts = [ 'ai_analysis' => 'array',