Support the ongoing development of Laravel.io →
posted 1 year ago
0

Hello Ciccios, Can you explain what actually your problem is? Is the code snippet you want to save stored in JSON format?

0

hi faisal, thank you for the response. i try to explain better the scenario.

i have a FE application, that send a similar json of the firt post.

in laravel server i have masterController and detailController, with models etc.

the FE application send the json at the master route, in the method i want to save the details too (details key of json).

i have tried the foreach loop for save every detail object, i need to save the id of the master in the object, but the single element of the foreach it's an array, tried do encode and decode the array but i have or "Call to undefined method stdClass::except()" error or message "Call to a member function except() on string". i understand the errors but can't approach to resolve.

the code of the loop cycle:

foreach($detalisAll as $detailsScratch ){

                      $JsonDetails = json_encode($detailsScratch ); // tried too json_decode(json_encode($detailsScratch ))
                      
                      $DetailToAdd = new Detail();
                      $DetailsToPost =  $JsonDetails ->except('ID', 'totale');

                      $DetailsToPost ->document_id = $request->ID;
                      $DetailToAdd ->fill($DetailsToPost );
                      $DetailSucces = $DetailToAdd ->save();
                      $DetailData = $DetailToAdd ->update($DetailData );



            }


thank you again.

Last updated 1 year ago.
0

The error you are getting is straightforward, you cannot use except method on the JSON string.

Now to help you to save the details I need to see the snippet of the data stored in the $detalisAll variable so that I can guide you on how to store the data in the database.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ciccios nexus6ita Joined 4 May 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.