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) { return $this->repository ->setPresenter(\Litepie\Medium\Repositories\Presenter\VariantPresenter::class) ->paginate(); } /** * Display variant. * * @param Request $request * @param Model $variant * * @return Response */ public function show(VariantRequest $request, Variant $variant) { return $variant->setPresenter(\Litepie\Medium\Repositories\Presenter\VariantListPresenter::class); ; } /** * Create new variant. * * @param Request $request * * @return Response */ public function store(VariantRequest $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('medium::variant.name')]); $code = 204; $status = 'success'; $url = guard_url('medium/variant/' . $variant->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('medium/variant'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the variant. * * @param Request $request * @param Model $variant * * @return Response */ public function update(VariantRequest $request, Variant $variant) { try { $data = $request->all(); $variant->update($data); $message = trans('messages.success.updated', ['Module' => trans('medium::variant.name')]); $code = 204; $status = 'success'; $url = guard_url('medium/variant/' . $variant->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('medium/variant/' . $variant->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the variant. * * @param Model $variant * * @return Response */ public function destroy(VariantRequest $request, Variant $variant) { try { $variant->delete(); $message = trans('messages.success.deleted', ['Module' => trans('medium::variant.name')]); $code = 202; $status = 'success'; $url = guard_url('medium/variant/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('medium/variant/' . $variant->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); } }