1

I have some JSON data; I decode that JSON data into an array, now I need to save the link column, id column and username column into my database table (the table name may be the product). So how to insert/save this column into the database in Laravel? My single node array structure format is below.

   {
        0 => {
          +"attribution": null
          +"tags": array:11 
          +"type": "image"
          +"location": null
          +"filter": "Normal"
          +"created_time": ""
          +"link": "https://www.url.com/p/myimage1/"
          +"id": "4354"
          +"user": {
            +"username": "user"
            +"profile_picture": "https://mypic.jpg"
            +"id": "224"
            +"full_name": ""
          }
        }
       
        }

6
  • What is the issue? 1) Create a class object 2) set object property value 3) save object. Commented Jun 6, 2016 at 11:56
  • Read this Commented Jun 6, 2016 at 12:00
  • @RaviHirani the link which you given according to this create a new record in the database,but my problem is different,i already have array data i need to save this data into my data base product table. Commented Jun 6, 2016 at 13:13
  • @raj: in that case you need to find record by PK. see this link:- Retrieving Single Models / Aggregates Commented Jun 6, 2016 at 13:30
  • laravel.com/docs/5.2/eloquent Commented Jun 6, 2016 at 13:37

2 Answers 2

2

One way to do that is to save original json data or convert array to json with ->toJson() or json_encode() and save it to a DB as Json data:

$table->json('options'); // JSON equivalent for the database.

https://laravel.com/docs/5.2/migrations#writing-migrations

Sign up to request clarification or add additional context in comments.

Comments

1

you can use toJson() method for it as below:

$table->toJson('options');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.