Last active
May 16, 2018 12:05
-
-
Save aynm142/f740901e9168501a2f788006f3d97857 to your computer and use it in GitHub Desktop.
task.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment