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