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