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