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