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