laravel create text file

Solutions on MaxInterview for laravel create text file by the best coders in the world

showing results for - "laravel create text file"
Brennan
13 Oct 2018
1namespace App\Http\Controllers;
2use File;
3class FileController extends Controller
4{
5    public function downloadJSONFile(){
6      $data = json_encode(['Element 1','Element 2','Element 3','Element 4','Element 5']);
7      $file = time() .rand(). '_file.json';
8      $destinationPath=public_path()."/upload/";
9      if (!is_dir($destinationPath)) {  mkdir($destinationPath,0777,true);  }
10      File::put($destinationPath.$file,$data);
11      return response()->download($destinationPath.$file);
12    }
13}