Hi! I created two models “Events” and “Organizers”. Organizers can be assigned to events via the $belongsToMany relationship. I want to add additional pivot fields that can be filled when assigning an organizer. Everything works great, but if I add repeater field I get the error “Array to String conversion error” when I press the “Add” button. How to fix this problem?
Hey @Radek
You may need to post the full stack trace so we can see what is happening. It is found in the storage/logs directory.
Here is the stack trace:
[2024-06-24 12:54:37] local.ERROR: ErrorException: Array to string conversion in I:\...\vendor\laravel\framework\src\Illuminate\Support\Str.php:835
Stack trace:
#0 I:\...\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(270): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Array to string...', 'I:\\...', 835)
#1 I:\...\vendor\laravel\framework\src\Illuminate\Support\Str.php(835): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(2, 'Array to string...', 'I:\\...', 835)
#2 I:\...\vendor\laravel\framework\src\Illuminate\Database\QueryException.php(57): Illuminate\Support\Str::replaceArray('?', Array, 'insert into `ss...')
#3 I:\...\vendor\laravel\framework\src\Illuminate\Database\QueryException.php(40): Illuminate\Database\QueryException->formatMessage('insert into `ss...', Array, Object(ErrorException))
#4 I:\...\vendor\laravel\framework\src\Illuminate\Database\Connection.php(761): Illuminate\Database\QueryException->__construct('insert into `ss...', Array, Object(ErrorException))
#5 I:\...\vendor\laravel\framework\src\Illuminate\Database\Connection.php(720): Illuminate\Database\Connection->runQueryCallback('insert into `ss...', Array, Object(Closure))
#6 I:\...\vendor\laravel\framework\src\Illuminate\Database\Connection.php(546): Illuminate\Database\Connection->run('insert into `ss...', Array, Object(Closure))
#7 I:\...\vendor\laravel\framework\src\Illuminate\Database\Connection.php(498): Illuminate\Database\Connection->statement('insert into `ss...', Array)
#8 I:\...\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(3274): Illuminate\Database\Connection->insert('insert into `ss...', Array)
#9 I:\...\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithPivotTable.php(272): Illuminate\Database\Query\Builder->insert(Array)
#10 I:\...\vendor\october\rain\src\Database\Relations\BelongsToMany.php(118): Illuminate\Database\Eloquent\Relations\BelongsToMany->attach(Array, Array, false)
#11 I:\...\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithPivotTable.php(178): October\Rain\Database\Relations\BelongsToMany->attach(1, Array, false)
#12 I:\...\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Relations\Concerns\InteractsWithPivotTable.php(114): Illuminate\Database\Eloquent\Relations\BelongsToMany->attachNew(Array, Array, false)
#13 I:\...\modules\backend\behaviors\relationcontroller\HasPivotMode.php(151): Illuminate\Database\Eloquent\Relations\BelongsToMany->sync(Array, false)
#14 I:\...\vendor\laravel\framework\src\Illuminate\Database\Concerns\ManagesTransactions.php(30): Backend\Behaviors\RelationController->Backend\Behaviors\RelationController\{closure}(Object(October\Rain\Database\Connections\MySqlConnection))
#15 I:\...\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(469): Illuminate\Database\Connection->transaction(Object(Closure))
#16 I:\...\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(338): Illuminate\Database\DatabaseManager->__call('transaction', Array)
#17 I:\...\modules\backend\behaviors\relationcontroller\HasPivotMode.php(175): Illuminate\Support\Facades\Facade::__callStatic('transaction', Array)
#18 [internal function]: Backend\Behaviors\RelationController->onRelationManagePivotCreate('1')
#19 I:\...\vendor\october\rain\src\Extension\ExtendableTrait.php(504): call_user_func_array(Array, Array)
#20 I:\...\vendor\october\rain\src\Extension\Extendable.php(55): October\Rain\Extension\Extendable->extendableCall('onRelationManag...', Array)
#21 I:\...\modules\system\traits\DependencyMaker.php(29): October\Rain\Extension\Extendable->__call('onRelationManag...', Array)
#22 I:\...\modules\backend\classes\Controller.php(646): Backend\Classes\Controller->makeCallMethod(Object(MY\Events\Controllers\Events), 'onRelationManag...', Array)
#23 I:\...\modules\backend\classes\Controller.php(457): Backend\Classes\Controller->runAjaxHandler('onRelationManag...')
#24 I:\...\modules\backend\classes\Controller.php(265): Backend\Classes\Controller->execAjaxHandlers()
#25 I:\...\modules\backend\classes\BackendController.php(137): Backend\Classes\Controller->run('update', Array)
#26 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(54): Backend\Classes\BackendController->run('my/events...')
#27 I:\...\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php(43): Illuminate\Routing\Controller->callAction('run', Array)
#28 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Route.php(260): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Backend\Classes\BackendController), 'run')
#29 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Route.php(205): Illuminate\Routing\Route->runController()
#30 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Router.php(798): Illuminate\Routing\Route->run()
#31 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#32 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#33 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#34 I:\...\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#35 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 I:\...\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#37 I:\...\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#38 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#39 I:\...\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#40 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 I:\...\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#42 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#43 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#44 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Router.php(799): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#45 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Router.php(776): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#46 I:\...\vendor\laravel\framework\src\Illuminate\Routing\Router.php(740): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#47 I:\...\vendor\october\rain\src\Router\CoreRouter.php(32): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#48 I:\...\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(190): October\Rain\Router\CoreRouter->dispatch(Object(Illuminate\Http\Request))
#49 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(141): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#50 I:\...\plugins\offline\responsiveimages\classes\ResponsiveImagesMiddleware.php(30): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#51 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): OFFLINE\ResponsiveImages\Classes\ResponsiveImagesMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#52 I:\...\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#53 I:\...\vendor\october\rain\src\Foundation\Http\Middleware\CheckForMaintenanceMode.php(23): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))
#54 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(180): October\Rain\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#55 I:\...\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(116): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#56 I:\...\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(165): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#57 I:\...\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(134): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#58 I:\...\index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#59 I:\...\vendor\october\rain\src\Foundation\resources\server.php(18): require_once('I:\\...')
#60 {main}
Did you add the repeater field to the jsonable
attribute in your model?
That might be the problem here.