repository = $task; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Worksheet\Task\Repositories\Criteria\TaskResourceCriteria::class); } /** * Display a list of task. * * @return Response */ public function index(TaskRequest $request) { return $this->repository ->setPresenter(\Worksheet\Task\Repositories\Presenter\TaskPresenter::class) ->paginate(); } /** * Display task. * * @param Request $request * @param Model $task * * @return Response */ public function show(TaskRequest $request, Task $task) { return $task->setPresenter(\Worksheet\Task\Repositories\Presenter\TaskListPresenter::class); ; } /** * Create new task. * * @param Request $request * * @return Response */ public function store(TaskRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('task::task.name')]); $code = 204; $status = 'success'; $url = guard_url('task/task/' . $task->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('task/task'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the task. * * @param Request $request * @param Model $task * * @return Response */ public function update(TaskRequest $request, Task $task) { try { $data = $request->all(); $task->update($data); $message = trans('messages.success.updated', ['Module' => trans('task::task.name')]); $code = 204; $status = 'success'; $url = guard_url('task/task/' . $task->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('task/task/' . $task->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the task. * * @param Model $task * * @return Response */ public function destroy(TaskRequest $request, Task $task) { try { $task->delete(); $message = trans('messages.success.deleted', ['Module' => trans('task::task.name')]); $code = 202; $status = 'success'; $url = guard_url('task/task/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('task/task/' . $task->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }