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