You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

  1. <?php
  2. namespace App\Models;
  3. use App\Models\Model;
  4. class Tag extends Model
  5. {
  6. protected $fillable = ['business_id', 'label', 'color'];
  7. protected $reportable = [
  8. 'label', 'color'
  9. ];
  10. public function getValueOf(?string $key)
  11. {
  12. $values = [
  13. 'business_id' => $this->business_id,
  14. 'project_id' => null,
  15. 'sprint_id' => null,
  16. 'workflow_id' => null,
  17. 'status_id' => null,
  18. 'system_id' => null,
  19. 'user_id' => null,
  20. 'task_id' => null,
  21. 'subject_id' => $this->id,
  22. ];
  23. if ($key && isset($values, $key)) {
  24. return $values[$key];
  25. }
  26. return $values;
  27. }
  28. public function rules()
  29. {
  30. return [
  31. 'label' => 'required|string|min:3|max:225',
  32. 'color' => 'nullable|string|min:2|max:255',
  33. ];
  34. }
  35. public function business()
  36. {
  37. return $this->belongsTo(Business::class,'business_id','id',__FUNCTION__);
  38. }
  39. public function task()
  40. {
  41. return $this->belongsToMany(
  42. Task::class,'tag_task','tag_id','task_id',
  43. 'id','id',__FUNCTION__
  44. );
  45. }
  46. }