Skip to content

Commit

Permalink
array_to_json_file_create_download
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammerHasan committed Jul 26, 2021
1 parent 397589c commit 40e4a86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .idea/laravel-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions array_to_json_file_create_download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

public function post()
{
$subjects = array_map(static function ($subjectsArr) {
return [
'id' => $subjectsArr['id'],
'ref' => $subjectsArr['reference']['name'],
];
}, \App\Post::with('reference')->orderBy('id', 'ASC')->get()->toArray());
$data = json_encode($subjects,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
header('Content-type: application/json; charset=UTF-8');
$file = 'posts.json';
$destinationPath=public_path()."/upload/json/";
if (!is_dir($destinationPath)) { mkdir($destinationPath,0777,true); }
File::put($destinationPath.$file,$data);
return response()->download($destinationPath.$file);
}

0 comments on commit 40e4a86

Please sign in to comment.