Refactor Product and Category Tables for Enhanced Localization: Updated the ProductCategoriesTable and ProductsTable to utilize the getStateUsing method for retrieving translated titles, improving localization support. Enhanced the search functionality to filter by translations, ensuring consistent display of titles across different languages. Additionally, modified the menu-item Blade component to include featured products, improving the layout and user experience.
This commit is contained in:
@@ -18,14 +18,19 @@ class ProductCategoriesTable
|
||||
->columns([
|
||||
TextColumn::make('title')
|
||||
->label(__('product_categories.title'))
|
||||
->formatStateUsing(fn ($state, $record) => $record->translate('title'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->getStateUsing(fn ($record) => $record->translate('title'))
|
||||
->searchable(query: function ($query, $search) {
|
||||
return $query->whereHas('translations', function ($q) use ($search) {
|
||||
$q->where('field_name', 'title')
|
||||
->where('field_value', 'like', "%{$search}%")
|
||||
->where('language_code', app()->getLocale());
|
||||
});
|
||||
}),
|
||||
TextColumn::make('slug')
|
||||
->label(__('product_categories.slug'))
|
||||
->searchable(),
|
||||
TextColumn::make('parent.title')
|
||||
->formatStateUsing(fn ($state, $record) => $record->parent?->translate('title'))
|
||||
->getStateUsing(fn ($record) => $record->parent?->translate('title'))
|
||||
->label(__('product_categories.parent')),
|
||||
TextColumn::make('sort_order')
|
||||
->label(__('product_categories.sort_order'))
|
||||
|
||||
@@ -18,12 +18,18 @@ class ProductsTable
|
||||
return $table
|
||||
->columns([
|
||||
ImageColumn::make('hero_image')
|
||||
->label(__('products.hero_image')),
|
||||
->label(__('products.hero_image'))
|
||||
->disk('public'),
|
||||
TextColumn::make('title')
|
||||
->label(__('products.title'))
|
||||
->formatStateUsing(fn ($state, $record) => $record->translate('title'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->getStateUsing(fn ($record) => $record->translate('title'))
|
||||
->searchable(query: function ($query, $search) {
|
||||
return $query->whereHas('translations', function ($q) use ($search) {
|
||||
$q->where('field_name', 'title')
|
||||
->where('field_value', 'like', "%{$search}%")
|
||||
->where('language_code', app()->getLocale());
|
||||
});
|
||||
}),
|
||||
TextColumn::make('type')
|
||||
->label(__('products.type'))
|
||||
->badge()
|
||||
@@ -38,7 +44,7 @@ class ProductsTable
|
||||
default => $state,
|
||||
}),
|
||||
TextColumn::make('category.title')
|
||||
->formatStateUsing(fn ($state, $record) => $record->category?->translate('title'))
|
||||
->getStateUsing(fn ($record) => $record->category?->translate('title'))
|
||||
->label(__('products.category')),
|
||||
ToggleColumn::make('is_active')
|
||||
->label(__('products.is_active')),
|
||||
|
||||
Reference in New Issue
Block a user