classic-o / nova-media-library

Media Library for admin panel "Laravel Nova"
MIT License
157 stars 66 forks source link

Array to String conversion - There was a problem submitting the form. "" #52

Closed tylerpixelguild closed 3 years ago

tylerpixelguild commented 3 years ago

I've got it working beautifully with a single file upload but when I try to allow multiple files by adding ->array() I get the following error when I try to submit the form for the resource to create.

Array to String conversion - There was a problem submitting the form. ""

It allows me to select multiple images and they display on the page but gives that error on submit.

This is the way I'm using it:

MediaLibrary::make('Image')->array('gallery'),

The column in the database is called "image" and is of the type "text".

    "php": "^7.3|^8.0",
    "benjaminhirsch/nova-slug-field": "^1.2",
    "classic-o/nova-media-library": "^1.0",
    "fideloper/proxy": "^4.4",
    "fruitcake/laravel-cors": "^2.0",
    "guzzlehttp/guzzle": "^7.0.1",
    "laravel/framework": "^8.12",
    "laravel/nova": "~3.0",
    "laravel/tinker": "^2.5",
    "league/flysystem-aws-s3-v3": "^1.0"

If I submit the form without the ->array() option it saves and shows the image properly. I can then add the ->array() option and edit the content and add multiple images without error. It only seems to happen when submitting new content not on editing.

tylerpixelguild commented 3 years ago

Sorry, I forgot to add my stack trace.

[2020-12-06 21:14:23] local.ERROR: Array to string conversion {"userId":1,"exception":"[object] (ErrorException(code: 0): Array to string conversion at /vendor/laravel/framework/src/Illuminate/Support/Str.php:494) [stacktrace]

0 /vendor/laravel/framework/src/Illuminate/Support/Str.php(494): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Array to string...', '...', 494, Array)

1 /vendor/laravel/framework/src/Illuminate/Database/QueryException.php(57): Illuminate\Support\Str::replaceArray('?', Array, 'insert into `ai...')

2 /vendor/laravel/framework/src/Illuminate/Database/QueryException.php(40): Illuminate\Database\QueryException->formatMessage('insert into `ai...', Array, Object(ErrorException))

3 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(679): Illuminate\Database\QueryException->__construct('insert into `ai...', Array, Object(ErrorException))

4 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(638): Illuminate\Database\Connection->runQueryCallback('insert into `ai...', Array, Object(Closure))

5 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(472): Illuminate\Database\Connection->run('insert into `ai...', Array, Object(Closure))

6 /vendor/laravel/framework/src/Illuminate/Database/Connection.php(424): Illuminate\Database\Connection->statement('insert into `ai...', Array)

7 /vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php(32): Illuminate\Database\Connection->insert('insert into `ai...', Array)

8 /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2872): Illuminate\Database\Query\Processors\Processor->processInsertGetId(Object(Illuminate\Database\Query\Builder), 'insert into `ai...', Array, 'id')

9 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1508): Illuminate\Database\Query\Builder->insertGetId(Array, 'id')

10 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1051): Illuminate\Database\Eloquent\Builder->__call('insertGetId', Array)

11 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1016): Illuminate\Database\Eloquent\Model->insertAndSetId(Object(Illuminate\Database\Eloquent\Builder), Array)

12 /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(857): Illuminate\Database\Eloquent\Model->performInsert(Object(Illuminate\Database\Eloquent\Builder))

13 /vendor/laravel/nova/src/Http/Controllers/ResourceStoreController.php(36): Illuminate\Database\Eloquent\Model->save()

14 /vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(29): Laravel\Nova\Http\Controllers\ResourceStoreController->Laravel\Nova\Http\Controllers\{closure}(Object(Illuminate\Database\MySqlConnection))

15 /vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php(371): Illuminate\Database\Connection->transaction(Object(Closure))

16 /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Database\DatabaseManager->__call('transaction', Array)

17 /vendor/laravel/nova/src/Http/Controllers/ResourceStoreController.php(44): Illuminate\Support\Facades\Facade::__callStatic('transaction', Array)

18 /vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Laravel\Nova\Http\Controllers\ResourceStoreController->handle(Object(Laravel\Nova\Http\Requests\CreateResourceRequest), 'ai-articles')

19 /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('handle', Array)

20 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(254): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Laravel\Nova\Http\Controllers\ResourceStoreController), 'handle')

21 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(197): Illuminate\Routing\Route->runController()

22 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(692): Illuminate\Routing\Route->run()

23 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))

24 /vendor/laravel/nova/src/Http/Middleware/Authorize.php(18): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

25 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Laravel\Nova\Http\Middleware\Authorize->handle(Object(Illuminate\Http\Request), Object(Closure))

26 /vendor/laravel/nova/src/Http/Middleware/BootTools.php(20): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

27 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Laravel\Nova\Http\Middleware\BootTools->handle(Object(Illuminate\Http\Request), Object(Closure))

28 /vendor/laravel/nova/src/Http/Middleware/DispatchServingNovaEvent.php(20): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

29 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Laravel\Nova\Http\Middleware\DispatchServingNovaEvent->handle(Object(Illuminate\Http\Request), Object(Closure))

30 /vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

31 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))

32 /vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

33 /vendor/laravel/nova/src/Http/Middleware/Authenticate.php(31): Illuminate\Auth\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure))

34 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Laravel\Nova\Http\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure))

35 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(77): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

36 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))

37 /vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

38 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))

39 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

40 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\Session\Middleware\StartSession->handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))

41 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))

42 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

43 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))

44 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

45 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))

46 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

47 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(694): Illuminate\Pipeline\Pipeline->then(Object(Closure))

48 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(669): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))

49 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))

50 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(624): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))

51 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(166): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))

52 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))

53 /vendor/laravel/nova/src/Http/Middleware/ServeNova.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

54 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Laravel\Nova\Http\Middleware\ServeNova->handle(Object(Illuminate\Http\Request), Object(Closure))

55 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

56 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

57 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

58 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))

59 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

60 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))

61 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(87): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

62 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle(Object(Illuminate\Http\Request), Object(Closure))

63 /vendor/fruitcake/laravel-cors/src/HandleCors.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

64 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))

65 /vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

66 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))

67 /vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustHosts.php(48): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

68 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Http\Middleware\TrustHosts->handle(Object(Illuminate\Http\Request), Object(Closure))

69 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))

70 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(141): Illuminate\Pipeline\Pipeline->then(Object(Closure))

71 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))

72 /public/index.php(52): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))

73 .composer/vendor/laravel/valet/server.php(191): require('...')

74 {main}

"}

classic-o commented 3 years ago

Did you set casts in model?

tylerpixelguild commented 3 years ago

Did you set casts in model?

D'oh!

My bad. Thank you. Great package.

anas322 commented 2 years ago

can you tell me how do you solve this problem with casts the model @tylerpixelguild