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