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