my filament resource when i enter value its not saving in db and have error
this is my error
` SQLSTATE[HY000]: General error: 1364 Field 'value' doesn't have a default value
INSERT INTO
translations (
alias,
updated_at,
created_at) VALUES (fafafafa, 2024-10-18 09:11:24, 2024-10-18 09:11:24)
f but im enter value this is my code ```1 Reply
<?php
namespace App\Filament\Resources;
use App\Components\Data\Translations\Models\Translations;
use App\Filament\Resources\TranslationsResource\Pages;
use Illuminate\Database\Eloquent\Builder;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\Tabs\Tab;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
class TranslationsResource extends Resource
{
protected static ?string $model = Translations::class;
protected static ?string $navigationIcon = 'heroicon-o-language';
protected static ?string $navigationGroup = 'eCommerce';
public static function form(Form $form): Form
{
$tabs = self::getTranslationTabs($form->getRecord());
return $form
->schema([
Grid::make()->schema([
Tabs::make('Languages')->tabs($tabs),
])->columns(1),
Section::make()->schema([
TextInput::make('alias')
->label('Alias')
->required()
->unique(ignoreRecord: true),
])->columns(1)
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('alias')
->label('Alias'),
TextColumn::make('value')
->label("English Value")
->formatStateUsing(fn(Model $record): string => $record->getTranslation('value', 'en')),
TextColumn::make('value_sl')
->label("Sloven Value")
->state(function (Model $record): string {
return $record->getTranslation('value', 'sl');
})
])
->filters([
Filter::make('value')
->form([
TextInput::make('value')->label('Translations')->placeholder('Translations')
])->query(fn(Builder $query, $data): Builder => $query->where(function ($q) use ($data) {
$i = 0;
foreach (config("laravellocalization.supportedLocales") as $code => $locale) {
$func = $i > 0 ? 'orWhereRaw' : 'whereRaw';
$q->$func("UPPER(json_unquote(json_extract(
value
,'$."" . $code . ""'))) LIKE ?", ["%" . strtoupper($data['value']) . "%"]);
$i++;
}
}))
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ListTranslations::route('/'),
'create' => Pages\CreateTranslations::route('/create'),
'edit' => Pages\EditTranslations::route('/{record}/edit'),
];
}
public static function getTranslationTabs($model)
{
$locales = config("laravellocalization.supportedLocales");
$data = [];
foreach ($locales as $code => $locale) {
$data[] = Tab::make($code)->label($locale['native'])->columns(1)->schema([
TextInput::make('value' . $code)
->afterStateHydrated(function (TextInput $component, $state) use ($code, $model) {
$title = $model ? json_decode($model->getRawOriginal('value')) : null;
$title = $title && isset($title->{$code}) ? $title->{$code} : null;
$component->state($title);
})
->label('Value')
->required()
->markAsRequired(),
]);
}
return $data;
}
}