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