Skip to content

Commit 40e4a86

Browse files
author
ProgrammerHasan
committed
array_to_json_file_create_download
1 parent 397589c commit 40e4a86

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.idea/laravel-idea.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
public function post()
4+
{
5+
$subjects = array_map(static function ($subjectsArr) {
6+
return [
7+
'id' => $subjectsArr['id'],
8+
'ref' => $subjectsArr['reference']['name'],
9+
];
10+
}, \App\Post::with('reference')->orderBy('id', 'ASC')->get()->toArray());
11+
$data = json_encode($subjects,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
12+
header('Content-type: application/json; charset=UTF-8');
13+
$file = 'posts.json';
14+
$destinationPath=public_path()."/upload/json/";
15+
if (!is_dir($destinationPath)) { mkdir($destinationPath,0777,true); }
16+
File::put($destinationPath.$file,$data);
17+
return response()->download($destinationPath.$file);
18+
}

0 commit comments

Comments
 (0)