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.

58 lines
1.2 KiB

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