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