'datetime', 'updated_at' => 'datetime', 'due_date' => 'date', ]; // Relationships public function applicantUnit() { return $this->belongsTo(Unit::class, 'unit_id'); } public function targetUnit() { return $this->belongsTo(Unit::class, 'target_unit_id'); } public function responsibleUser() { return $this->belongsTo(User::class, 'responsible_user_id'); } public function createdByUser() { return $this->belongsTo(User::class, 'created_by_user_id'); } public function replies() { return $this->hasMany(KanbanReply::class, 'kanban_id'); } // Query Scopes public function scopeVisibleToUnit($query, int $unitId) { return $query->where(function ($q) use ($unitId) { // Cards created by this unit (origin = unit) $q->where('unit_id', $unitId) // Cards explicitly targeted at this unit (specific or broadcast-per-unit) ->orWhere('target_unit_id', $unitId); // Note: scope='all' is NOT used here — when broadcasting the controller // already creates one card per unit each with its own target_unit_id, // so filtering by target_unit_id is sufficient and correct. }); } }