form = RestaurantForm::setAttributes()->toArray(); $this->modules = $this->modules(config('litecms.restaurant.modules'), 'restaurant', guard_url('restaurant')); $this->repository = $restaurant; } /** * Display a list of restaurant. * * @return Response */ public function index(RestaurantRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(RestaurantResourceFilter::class) ->setPresenter(RestaurantListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('restaurant::restaurant.names')) ->view('restaurant::restaurant.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display restaurant. * * @param Request $request * @param Model $restaurant * * @return Response */ public function show(RestaurantRequest $request, RestaurantRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('restaurant::restaurant.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('restaurant::restaurant.show') ->output(); } /** * Show the form for creating a new restaurant. * * @param Request $request *x * @return Response */ public function create(RestaurantRequest $request, RestaurantRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('restaurant::restaurant.name')) ->view('restaurant::restaurant.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new restaurant. * * @param Request $request * * @return Response */ public function store(RestaurantRequest $request, RestaurantRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('restaurant::restaurant.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('restaurant/restaurant/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/restaurant/restaurant')) ->redirect(); } } /** * Show restaurant for editing. * * @param Request $request * @param Model $restaurant * * @return Response */ public function edit(RestaurantRequest $request, RestaurantRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('restaurant::restaurant.name')) ->view('restaurant::restaurant.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the restaurant. * * @param Request $request * @param Model $restaurant * * @return Response */ public function update(RestaurantRequest $request, RestaurantRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('restaurant::restaurant.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('restaurant/restaurant/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('restaurant/restaurant/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the restaurant. * * @param Model $restaurant * * @return Response */ public function destroy(RestaurantRequest $request, RestaurantRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('restaurant::restaurant.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('restaurant/restaurant/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('restaurant/restaurant/' . $repository->getRouteKey())) ->redirect(); } } }