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