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) { return $this->repository ->setPresenter(\Moblyze\Operation\Repositories\Presenter\OperationPresenter::class) ->paginate(); } /** * Display operation. * * @param Request $request * @param Model $operation * * @return Response */ public function show(OperationRequest $request, Operation $operation) { return $operation->setPresenter(\Moblyze\Operation\Repositories\Presenter\OperationListPresenter::class); ; } /** * Create new operation. * * @param Request $request * * @return Response */ public function store(OperationRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('operation::operation.name')]); $code = 204; $status = 'success'; $url = guard_url('operation/operation/' . $operation->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('operation/operation'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the operation. * * @param Request $request * @param Model $operation * * @return Response */ public function update(OperationRequest $request, Operation $operation) { try { $data = $request->all(); $operation->update($data); $message = trans('messages.success.updated', ['Module' => trans('operation::operation.name')]); $code = 204; $status = 'success'; $url = guard_url('operation/operation/' . $operation->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('operation/operation/' . $operation->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the operation. * * @param Model $operation * * @return Response */ public function destroy(OperationRequest $request, Operation $operation) { try { $operation->delete(); $message = trans('messages.success.deleted', ['Module' => trans('operation::operation.name')]); $code = 202; $status = 'success'; $url = guard_url('operation/operation/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('operation/operation/' . $operation->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }