Kanban.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * @property int $id
  8. * @property int|null $unit_id Unidade que criou o card (nulo para Matriz)
  9. * @property string $title
  10. * @property string|null $description
  11. * @property string $phase a_fazer|em_progresso|em_revisao|concluido|demandas_especiais
  12. * @property string $priority alta|normal|baixa
  13. * @property string $origin matriz|unit
  14. * @property string $scope internal|all|specific
  15. * @property string|null $sector
  16. * @property string|null $due_date
  17. * @property int|null $responsible_user_id
  18. * @property int|null $created_by_user_id
  19. * @property int|null $target_unit_id
  20. * @property \Illuminate\Support\Carbon|null $created_at
  21. * @property \Illuminate\Support\Carbon|null $updated_at
  22. * @property string|null $deleted_at
  23. * @mixin \Eloquent
  24. */
  25. class Kanban extends Model
  26. {
  27. use HasFactory, SoftDeletes;
  28. protected $table = 'kanbans';
  29. protected $guarded = ['id'];
  30. protected $casts = [
  31. 'created_at' => 'datetime',
  32. 'updated_at' => 'datetime',
  33. 'due_date' => 'date',
  34. ];
  35. // Relationships
  36. public function applicantUnit()
  37. {
  38. return $this->belongsTo(Unit::class, 'unit_id');
  39. }
  40. public function targetUnit()
  41. {
  42. return $this->belongsTo(Unit::class, 'target_unit_id');
  43. }
  44. public function responsibleUser()
  45. {
  46. return $this->belongsTo(User::class, 'responsible_user_id');
  47. }
  48. public function createdByUser()
  49. {
  50. return $this->belongsTo(User::class, 'created_by_user_id');
  51. }
  52. public function replies()
  53. {
  54. return $this->hasMany(KanbanReply::class, 'kanban_id');
  55. }
  56. // Query Scopes
  57. public function scopeVisibleToUnit($query, int $unitId)
  58. {
  59. return $query->where(function ($q) use ($unitId) {
  60. $q->where('unit_id', $unitId)
  61. ->orWhere('target_unit_id', $unitId)
  62. ->orWhere('scope', 'all');
  63. });
  64. }
  65. }