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