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