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