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