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