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