repository = $todo; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepci\Todo\Repositories\Criteria\TodoResourceCriteria::class); } /** * Display a list of todo. * * @return Response */ public function index(TodoRequest $request) { return $this->repository ->setPresenter(\Litepci\Todo\Repositories\Presenter\TodoPresenter::class) ->paginate(); } /** * Display todo. * * @param Request $request * @param Model $todo * * @return Response */ public function show(TodoRequest $request, Todo $todo) { return $todo->setPresenter(\Litepci\Todo\Repositories\Presenter\TodoListPresenter::class); ; } /** * Create new todo. * * @param Request $request * * @return Response */ public function store(TodoRequest $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('todo::todo.name')]); $code = 204; $status = 'success'; $url = guard_url('todo/todo/' . $todo->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('todo/todo'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the todo. * * @param Request $request * @param Model $todo * * @return Response */ public function update(TodoRequest $request, Todo $todo) { try { $data = $request->all(); $todo->update($data); $message = trans('messages.success.updated', ['Module' => trans('todo::todo.name')]); $code = 204; $status = 'success'; $url = guard_url('todo/todo/' . $todo->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('todo/todo/' . $todo->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the todo. * * @param Model $todo * * @return Response */ public function destroy(TodoRequest $request, Todo $todo) { try { $todo->delete(); $message = trans('messages.success.deleted', ['Module' => trans('todo::todo.name')]); $code = 202; $status = 'success'; $url = guard_url('todo/todo/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('todo/todo/' . $todo->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); } }