2
0

ProjectApi.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 'weight' => $project->weight,
  20. 'description' => $project->description,
  21. ];
  22. } else {
  23. return null;
  24. }
  25. }
  26. public static function getListByIds($ids)
  27. {
  28. if (!$ids) {
  29. return null;
  30. };
  31. $projects = Project::whereIn('uid', $ids)->get();
  32. $output = array();
  33. foreach ($ids as $key => $id) {
  34. foreach ($projects as $project) {
  35. if ($project->uid === $id) {
  36. $output[] = [
  37. 'id' => $id,
  38. 'title' => $project->title,
  39. 'type' => $project->type,
  40. 'weight' => $project->weight,
  41. 'description' => $project->description,
  42. ];
  43. continue;
  44. };
  45. }
  46. }
  47. return $output;
  48. }
  49. }