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