repository = $deliverable; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepci\Service\Repositories\Criteria\DeliverableResourceCriteria::class); } /** * Display a list of deliverable. * * @return Response */ public function index(DeliverableRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litepci\Service\Repositories\Presenter\DeliverablePresenter::class) ->$function(); } $deliverables = $this->repository->paginate(); return $this->response->setMetaTitle(trans('service::deliverable.names')) ->view('service::deliverable.index', true) ->data(compact('deliverables', 'view')) ->output(); } /** * Display deliverable. * * @param Request $request * @param Model $deliverable * * @return Response */ public function show(DeliverableRequest $request, Deliverable $deliverable) { if ($deliverable->exists) { $view = 'service::deliverable.show'; } else { $view = 'service::deliverable.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('service::deliverable.name')) ->data(compact('deliverable')) ->view($view, true) ->output(); } /** * Show the form for creating a new deliverable. * * @param Request $request * * @return Response */ public function create(DeliverableRequest $request) { $deliverable = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('service::deliverable.name')) ->view('service::deliverable.create', true) ->data(compact('deliverable')) ->output(); } /** * Create new deliverable. * * @param Request $request * * @return Response */ public function store(DeliverableRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $deliverable = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('service::deliverable.name')])) ->code(204) ->status('success') ->url(guard_url('service/deliverable/' . $deliverable->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/service/deliverable')) ->redirect(); } } /** * Show deliverable for editing. * * @param Request $request * @param Model $deliverable * * @return Response */ public function edit(DeliverableRequest $request, Deliverable $deliverable) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('service::deliverable.name')) ->view('service::deliverable.edit', true) ->data(compact('deliverable')) ->output(); } /** * Update the deliverable. * * @param Request $request * @param Model $deliverable * * @return Response */ public function update(DeliverableRequest $request, Deliverable $deliverable) { try { $attributes = $request->all(); $deliverable->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('service::deliverable.name')])) ->code(204) ->status('success') ->url(guard_url('service/deliverable/' . $deliverable->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('service/deliverable/' . $deliverable->getRouteKey())) ->redirect(); } } /** * Remove the deliverable. * * @param Model $deliverable * * @return Response */ public function destroy(DeliverableRequest $request, Deliverable $deliverable) { try { $deliverable->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('service::deliverable.name')])) ->code(202) ->status('success') ->url(guard_url('service/deliverable/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('service/deliverable/' . $deliverable->getRouteKey())) ->redirect(); } } /** * Remove multiple deliverable. * * @param Model $deliverable * * @return Response */ public function delete(DeliverableRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('service::deliverable.name')])) ->status("success") ->code(202) ->url(guard_url('service/deliverable')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/service/deliverable')) ->redirect(); } } /** * Restore deleted deliverables. * * @param Model $deliverable * * @return Response */ public function restore(DeliverableRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('service::deliverable.name')])) ->status("success") ->code(202) ->url(guard_url('/service/deliverable')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/service/deliverable/')) ->redirect(); } } }