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