Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function newTasks(Request $request)
- {
- // callback for return all tasks
- $returnResponse = function($tasks) {
- $response = [];
- foreach ($tasks as $task) {
- $response[] = [
- 'id' => $task->id,
- 'package_name' => $task->package_name,
- 'title' => $task->title,
- 'status' => $task->status,
- 'image_url' => $task->image_url,
- 'award' => $task->award,
- 'daily_award' => $task->daily_arard,
- 'type' => $task->type,
- 'amount' => $task->amount,
- 'keywords' => $task->keywords,
- ];
- }
- return $response;
- };
- // get viewed tasks
- $user_tasks = $this->user->tasks()->whereIsChecked(1)->get();
- // if tasks array is not empty
- if ($user_tasks->isNotEmpty()) {
- // get theirs ids
- $taskIds = $user_tasks->pluck('id');
- // get only not checked tasks
- $notCheckedTasks = Task::whereNotIn('id', $taskIds)->limit($request->get('start'))->offset($request->get('offset'))->get();
- return new JsonResponse(
- $returnResponse($notCheckedTasks),
- 200);
- }
- // get only completed tasks
- $user_tasks = $this->user->tasks()->whereDone(1)->get();
- // get theirs ids
- $taskIds = $user_tasks->pluck('id');
- // get only not checked tasks
- $notCheckedTasks = Task::whereNotIn('id', $taskIds)->limit($request->get('start'))->offset($request->get('offset'))->get();
- return new JsonResponse(
- $returnResponse($notCheckedTasks),
- 200);
- }
Add Comment
Please, Sign In to add comment