column data in exporter
this is the code.
the output should be this
but i am getting only this.
i am getting the values and not the key.
in the resource it is like this.
ExportColumn::make('data')->label('Data')
->formatStateUsing(function ($state) {
// Debug log the incoming state
\Log::info('Data State:', ['state' => $state, 'type' => gettype($state)]);
if (is_null($state)) {
return json_encode([]);
}
// Keep it simple: just encode the data as JSON
if (is_array($state)) {
return json_encode($state);
}
// If it's already a JSON string, return it
if (is_string($state)) {
// Check if it's valid JSON
json_decode($state);
if (json_last_error() === JSON_ERROR_NONE) {
return $state;
}
}
// For other types, convert to string
return (string)$state;
}),ExportColumn::make('data')->label('Data')
->formatStateUsing(function ($state) {
// Debug log the incoming state
\Log::info('Data State:', ['state' => $state, 'type' => gettype($state)]);
if (is_null($state)) {
return json_encode([]);
}
// Keep it simple: just encode the data as JSON
if (is_array($state)) {
return json_encode($state);
}
// If it's already a JSON string, return it
if (is_string($state)) {
// Check if it's valid JSON
json_decode($state);
if (json_last_error() === JSON_ERROR_NONE) {
return $state;
}
}
// For other types, convert to string
return (string)$state;
}),the output should be this
{"featured":true,"priority":1,"weather_resistant":true,"materials":["wood","metal","synthetic"]}{"featured":true,"priority":1,"weather_resistant":true,"materials":["wood","metal","synthetic"]}but i am getting only this.
true, 1, true, ["wood","metal","synthetic"]true, 1, true, ["wood","metal","synthetic"]i am getting the values and not the key.
in the resource it is like this.
Forms\Components\KeyValue::make('data')
->label(__('Additional Details'))
->columnSpanFull(), Forms\Components\KeyValue::make('data')
->label(__('Additional Details'))
->columnSpanFull(),