Refactor Product Category Form and Product Form: Updated the options method to use \Illuminate\Support\Arr::first for retrieving category titles, ensuring better handling of localization. Added a fallback for category titles to display a default message when no title is available, improving user experience in form submissions.

This commit is contained in:
Ümit Tunç
2025-12-30 22:16:51 +03:00
parent a85e6eebe0
commit f4cf16f93f
2 changed files with 4 additions and 4 deletions
@@ -26,9 +26,9 @@ class ProductCategoryForm
->options(function () { ->options(function () {
return ProductCategory::all()->mapWithKeys(function ($category) { return ProductCategory::all()->mapWithKeys(function ($category) {
$title = is_array($category->title) $title = is_array($category->title)
? ($category->title[app()->getLocale()] ?? first($category->title)) ? ($category->title[app()->getLocale()] ?? \Illuminate\Support\Arr::first($category->title))
: $category->title; : $category->title;
return [$category->id => $title]; return [$category->id => $title ?? ('Category #' . $category->id)];
}); });
}) })
->searchable(), ->searchable(),
@@ -33,9 +33,9 @@ class ProductForm
->options(function () { ->options(function () {
return ProductCategory::all()->mapWithKeys(function ($category) { return ProductCategory::all()->mapWithKeys(function ($category) {
$title = is_array($category->title) $title = is_array($category->title)
? ($category->title[app()->getLocale()] ?? first($category->title)) ? ($category->title[app()->getLocale()] ?? \Illuminate\Support\Arr::first($category->title))
: $category->title; : $category->title;
return [$category->id => $title]; return [$category->id => $title ?? ('Category #' . $category->id)];
}); });
}) })
->searchable(), ->searchable(),