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:
@@ -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(),
|
||||||
|
|||||||
Reference in New Issue
Block a user