| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- /**
- * @property int $id
- * @property int|null $unit_id Unidade que criou o card (nulo para Matriz)
- * @property string $title
- * @property string|null $description
- * @property string $phase a_fazer|em_progresso|em_revisao|concluido|demandas_especiais
- * @property string $priority alta|normal|baixa
- * @property string $origin matriz|unit
- * @property string $scope internal|all|specific
- * @property string|null $sector
- * @property string|null $due_date
- * @property int|null $responsible_user_id
- * @property int|null $created_by_user_id
- * @property int|null $target_unit_id
- * @property \Illuminate\Support\Carbon|null $created_at
- * @property \Illuminate\Support\Carbon|null $updated_at
- * @property string|null $deleted_at
- * @mixin \Eloquent
- */
- class Kanban extends Model
- {
- use HasFactory, SoftDeletes;
- protected $table = 'kanbans';
- protected $guarded = ['id'];
- protected $casts = [
- 'created_at' => '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) {
- $q->where('unit_id', $unitId)
- ->orWhere('target_unit_id', $unitId)
- ->orWhere('scope', 'all');
- });
- }
- }
|