php - Creating a laravel txt with some data from database in LARAVEL -
how can create method in laravel in user controller when click on button in view download txt file info tha generating query
user::select('id','name','lastname') ->orderby('id','desc') ->take(100) ->get();
printing these 3 fields of users table in 3 column in txt file. if can guide me doing via jquery-ajax perfect !
updated problem solved guy below !
//controller public function downloadtxt() { $txt = ""; $datas = user::select('id','name','lastname') ->orderby('id','desc') ->take(100) ->get(); foreach($datas $data){ $txt .= $data['id'].'|'.$data['name'].'|'.$data['lastname'].php_eol; } $txtname = 'mytxt.txt'; $headers = ['content-type'=>'text/plain', 'test'=>'yoyo', 'content-disposition'=>sprintf('attachment; filename="%s"', $txtname),'x-booyah'=>'workyworky','content-length'=>sizeof($datas)]; return \response::make($txt , 200, $headers ); }
Comments
Post a Comment