form = InternalForm::setAttributes()->toArray(); $this->modules = $this->modules(config('internal.internal.modules'), 'internal', guard_url('internal')); $this->repository = $internal; } /** * Display a list of internal. * * @return Response */ public function index(InternalRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(InternalResourceFilter::class) ->setPresenter(InternalListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('internal::internal.names')) ->view('internal::internal.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display internal. * * @param Request $request * @param Model $internal * * @return Response */ public function show(InternalRequest $request, InternalRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('internal::internal.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('internal::internal.show') ->output(); } /** * Show the form for creating a new internal. * * @param Request $request *x * @return Response */ public function create(InternalRequest $request, InternalRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('internal::internal.name')) ->view('internal::internal.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new internal. * * @param Request $request * * @return Response */ public function store(InternalRequest $request, InternalRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('internal::internal.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('internal/internal/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/internal/internal')) ->redirect(); } } /** * Show internal for editing. * * @param Request $request * @param Model $internal * * @return Response */ public function edit(InternalRequest $request, InternalRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('internal::internal.name')) ->view('internal::internal.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the internal. * * @param Request $request * @param Model $internal * * @return Response */ public function update(InternalRequest $request, InternalRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('internal::internal.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('internal/internal/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('internal/internal/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the internal. * * @param Model $internal * * @return Response */ public function destroy(InternalRequest $request, InternalRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('internal::internal.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('internal/internal/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('internal/internal/' . $repository->getRouteKey())) ->redirect(); } } }