Reputation: 614
I have a JSON file that I would like to load into a controller in Laravel so that I can use the data into my application.
The files path is /storage/app/calendar_Ids.json.
What is the correct way to go about doing this?
Upvotes: 9
Views: 29133
Reputation: 11
You can try this too:
$json = file_get_contents('your json file path here.....');
//converting json object to php associative array
$data = json_decode($json, true);
foreach($data as $item){
DB::table('table name')->insert(
array(
'clientId' => $item['clientId'],
'socialMediaLinkId' => $item['socialMediaLinkId'],
'link' => $item['link'],
'isEnabled' => $item['isEnabled'],
'created_at' => $item['created_at'],
'updated_at' => $item['updated_at'],
'isSelectedByDefault' =>$item['isSelectedByDefault'],
'showOnNegativePage' =>$item['showOnNegativePage']
)
);
}
Upvotes: 1
Reputation: 72
You can try this too:
$json = storage_path('folder/filename.json');
Upvotes: -1
Reputation: 5367
Here, this should help you get sorted.
use Storage;
$json = Storage::disk('local')->get('calendar_Ids.json');
$json = json_decode($json, true);
Upvotes: 21
Reputation: 2179
Try this
$path = '/storage/app/calendar_Ids.json';
$content = json_decode(file_get_contents($path), true);`
Then just dd($content);
to see if it works.
Upvotes: 5