Guest User

Untitled

a guest
May 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. public function newTasks(Request $request)
  2. {
  3. // callback for return all tasks
  4. $returnResponse = function($tasks) {
  5. $response = [];
  6. foreach ($tasks as $task) {
  7. $response[] = [
  8. 'id' => $task->id,
  9. 'package_name' => $task->package_name,
  10. 'title' => $task->title,
  11. 'status' => $task->status,
  12. 'image_url' => $task->image_url,
  13. 'award' => $task->award,
  14. 'daily_award' => $task->daily_arard,
  15. 'type' => $task->type,
  16. 'amount' => $task->amount,
  17. 'keywords' => $task->keywords,
  18. ];
  19. }
  20.  
  21. return $response;
  22. };
  23.  
  24. // get viewed tasks
  25. $user_tasks = $this->user->tasks()->whereIsChecked(1)->get();
  26.  
  27. // if tasks array is not empty
  28. if ($user_tasks->isNotEmpty()) {
  29.  
  30. // get theirs ids
  31. $taskIds = $user_tasks->pluck('id');
  32. // get only not checked tasks
  33. $notCheckedTasks = Task::whereNotIn('id', $taskIds)->limit($request->get('start'))->offset($request->get('offset'))->get();
  34.  
  35. return new JsonResponse(
  36. $returnResponse($notCheckedTasks),
  37. 200);
  38. }
  39.  
  40. // get only completed tasks
  41. $user_tasks = $this->user->tasks()->whereDone(1)->get();
  42. // get theirs ids
  43. $taskIds = $user_tasks->pluck('id');
  44. // get only not checked tasks
  45. $notCheckedTasks = Task::whereNotIn('id', $taskIds)->limit($request->get('start'))->offset($request->get('offset'))->get();
  46.  
  47. return new JsonResponse(
  48. $returnResponse($notCheckedTasks),
  49. 200);
  50. }
Add Comment
Please, Sign In to add comment