ProjectApi.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Models\Project;
  4. use Illuminate\Support\Facades\Log;
  5. use Illuminate\Support\Facades\App;
  6. class ProjectApi
  7. {
  8. public static function getById($id)
  9. {
  10. if (!$id) {
  11. return null;
  12. };
  13. $project = Project::find($id);
  14. if ($project) {
  15. return [
  16. 'id' => $id,
  17. 'title' => $project->title,
  18. 'type' => $project->type,
  19. 'description' => $project->description,
  20. ];
  21. } else {
  22. return null;
  23. }
  24. }
  25. public static function getListByIds($ids)
  26. {
  27. if (!$ids) {
  28. return null;
  29. };
  30. $projects = Project::whereIn('uid', $ids)->get();
  31. $output = array();
  32. foreach ($ids as $key => $id) {
  33. foreach ($projects as $project) {
  34. if ($project->uid === $id) {
  35. $output[] = [
  36. 'id' => $id,
  37. 'title' => $project->title,
  38. 'type' => $project->type,
  39. 'description' => $project->description,
  40. ];
  41. continue;
  42. };
  43. }
  44. }
  45. return $output;
  46. }
  47. }