SourceMatters.php 1017 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Model;
  5. class SourceMatters extends Model
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $table = 'base_source_matters';
  11. protected $guarded = [];
  12. protected $casts = [
  13. 'similar_name' => 'array'
  14. ];
  15. /**
  16. * The attributes excluded from the model's JSON form.
  17. *
  18. * @var array
  19. */
  20. protected $hidden = [];
  21. /**
  22. * 获取名称
  23. * @return array
  24. */
  25. public static function getNames()
  26. {
  27. $sourceMatters = self::query()->where('status', ModelStatusEnum::OK)->get();
  28. $data = [];
  29. foreach ($sourceMatters as $sourceMatter) {
  30. $da = $sourceMatter->similar_name;
  31. if (!is_array($da)) $da = [];
  32. $da[] = $sourceMatter->name;
  33. $data[] = [
  34. 'id' => $sourceMatter->id,
  35. 'names' => $da,
  36. ];
  37. }
  38. return $data;
  39. }
  40. }