ProjectApi.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. public static function getById($id){
  8. if(!$id){
  9. return null;
  10. };
  11. $project = Project::where('id',$id)->first();
  12. if($project){
  13. return [
  14. 'id'=>$id,
  15. 'title'=>$project->title,
  16. 'type'=>$project->type,
  17. 'description'=>$project->description,
  18. ];
  19. }else{
  20. return null;
  21. }
  22. }
  23. public static function getListByIds($ids){
  24. if(!$ids){
  25. return null;
  26. };
  27. $projects = Project::whereIn('id',$ids)->get();
  28. $output = array();
  29. foreach ($ids as $key => $id) {
  30. foreach ($projects as $project) {
  31. if($project->id === $id){
  32. $output[] = [
  33. 'id'=>$id,
  34. 'title'=>$project->title,
  35. 'type'=>$project->type,
  36. 'description'=>$project->description,
  37. ];
  38. continue;
  39. };
  40. }
  41. }
  42. return $output;
  43. }
  44. }