2016-04-01 5 views
0

jsonを解析し、すべてのデータをデータベースに保存します。ここ は私のJSONです:JSONArrayはlaravelを解析しています4

[{ 
"date": "2016/04/01", 
"mac": "C9:3F:C1:B1:6F:1F", 
"id": 16, 
"dest": 0, 
"melvalue": 22 
}, { 
"date": "2016/03/31", 
"mac": "C9:3F:C1:B1:6F:1F", 
"id": 1, 
"dest": 0, 
"melvalue": 0 
}, { 
"date": "2016/03/30", 
"mac": "C9:3F:C1:B1:6F:1F", 
"id": 2, 
"dest": 0, 
"melvalue": 0 
}] 

はどうすればこれを行うことができますか?助けてください。

{ 
"date": "2016/03/17", 
"mac": "C9:3F:C1:B1:6F:1F", 
"id": 15, 
"dest": 12, 
"melvalue": 0 
} 

は私の1列の表になります。

答えて

0

-Stepsは などのようになります - コントローラ機能のソースからのすべてのデータを読み込み

$arraytoIterate = json_decode('Yor json string here to go'); 

-- Create a model for that table 

-- create dataArray and save the data in your controllers function as below 

$arraytoIterate = json_decode('Yor json string here to go'); 

    foreach($arraytoIterate as $newArr){ 
     // hope table columns name will be same as of json object column name 
     ModelName::create($newArr) // for adding records 
    } 

関連する問題