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