/** * @param Menu $menu * @param MenuItem $item * @param Request $request * @param Page $page * @param Locale $locale * @param ModuleRoute $route * @return */ public function store(Menu $menu, MenuItem $item, Request $request, Page $page, Locale $locale, ModuleRoute $route) { $input = translation_input($request, ['name']); if (isset($input['page_id'])) { //make sure to set the default labels for the menu item $page = $page->findOrFail($input['page_id']); foreach ($locale->all() as $locale) { $translation = $page->translate($locale->slug); if ($translation) { $input[$locale->slug]['name'] = $translation->title; } } } elseif (isset($input['module_route_id'])) { //make sure to set the default labels for the menu item $route = $route->findOrFail($input['module_route_id']); foreach ($locale->all() as $locale) { $translation = $route->translate($locale->slug); if ($translation) { $input[$locale->slug]['name'] = $translation->title; } } } else { $rules = ['url' => 'required']; foreach ($this->account->account()->locales as $locale) { $rules = array_merge($rules, ["translations.{$locale->slug}.name" => 'required']); } $this->validate($request, $rules); } return $this->menu->createItem($input); }
/** * Get the collection of items as a plain array. * * @return array */ public function toArray() { $locales = Locale::all(); $translations = with(new Collection($this->items))->keyBy('locale_id')->toArray(); $result = []; foreach ($locales as $locale) { if (isset($translations[$locale->id])) { $result[$locale->slug] = $translations[$locale->id]; } } return $result; }
/** * @param Request $request * @param Product $product * @param Guard $guard * @param AccountManager $accounts * @return Product|string|static */ public function store(Request $request, Product $product, Guard $guard, AccountManager $accounts) { $this->validate($request, ['brand_id' => 'required|exists:product_brands,id', 'name' => 'required|string', 'ean' => 'string|size:13']); $input = translation_input($request); $name = $request->get('name'); foreach (Locale::all() as $locale) { $input[$locale->slug] = ['name' => $name]; } $product = $product->newInstance($input); $product->account_id = $accounts->account()->id; if ($product->save()) { return $product; } return json_encode(['status' => 'noke']); }
/** * keep this public, this allows for easy searching inheriting. * * @param Searchable $inheritFrom * @return array */ public function getSearchableSuggestData(Searchable $inheritFrom = null) { $data = []; if (uses_trait($this, Translatable::class)) { //foreach locale we add a different suggest foreach (Locale::all() as $locale) { $translation = $this->translate($locale->slug); if (!$translation) { continue; } $data[$this->getSearchableSuggestName($locale, $inheritFrom)] = $this->getSearchableSuggestPayload($translation); } } return $data; }