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