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