Repeater - Array to String Conversion when save - logImplodeAssoc
i am on my first testing to store json arrays into database with repeater.
- the database column was changed to JSON with a migration
- the Model got:
protected $casts = ['urls' => 'json'];
- output is also working
but a related error message will be thown when saving the form - i am not sure if i am doing something wrong, or it´s a bug:
Array to string conversion
/**
* Format an assoc array as a key/value string for logging
* @return string
*/
public static function logImplodeAssoc(array $attrs): string {
$l = '';
foreach( $attrs as $k => $v ) {
** $l .= "{ $k => $v } ";**
}
return $l;
}
Repeater:
Repeater::make('urls')->schema([
TextInput::make('Stream-URL')
])
->hidden(function(Get $get){
if(!in_array($get('type'),[9,7,11,10])){
return true;
}
return false;
}),
TextColumn:
TextColumn::make('outstream.urls')->state(function(Model $record){
$out = '';
foreach((array)$record->outipstream->urls as $url){
$out .= $url['Stream-URL'].' ';
}
return $out;
}),
Solution:Jump to solution
it says that function is in app/Traits/Observable.php, that is in your app, not filament or laravel.
5 Replies
Can you share your error message?
Flare
Array to string conversion - The error occurred at http://192.168.9.10:8200/admin/playouts/ahlten-htp/edit
the error happens in the function logImplodeAssoc which is not my code ... its from filament or laravel
i figured out something..... the error occurs in observable.php
if i change the function this way, the error is gone:
/**
* Format an assoc array as a key/value string for logging
* @return string
*/
public static function logImplodeAssoc(array $attrs): string {
$l = '';
foreach( $attrs as $k => $v ) {
/* changes Start */
if(is_array($v)){
continue;
} /* change End */
$l .= "{ $k => $v } ";
}
return $l;
}
when converting the array for logging ... it converts only one level - if multidimensional array comes to this function it breaks - i think it has to be fixed in filament sourceSolution
it says that function is in app/Traits/Observable.php, that is in your app, not filament or laravel.
i share this project with other developers.... i wasn´t aware, that it´s not from laravel... thanks for the hint