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