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