I'm writing a artisan command to export the table from my database as a csv file. But when im running the command, the CLI shows me only the data from the database and don't create a CSV File.
2条回答 默认 最新
- duangu1878 2017-07-26 14:36关注
this works fine in my laravel 5.4 project
public function handle() { $filename = "logins.csv"; $handle = fopen($filename, 'w'); fputcsv($handle, array('customer_id', 'count', 'year', 'month', 'day', 'hour')); fputcsv($handle, array("row['customer_id']", "row['count']", "row['year']", "row['month']", "row['day']", "row['hour']")); fclose($handle); $headers = array( 'Content-Type' => 'text/csv', ); }
creates file logins.csv in the project root directory
customer_id,count,year,month,day,hour row['customer_id'],row['count'],row['year'],row['month'],row['day'],row['hour']
btw what is purpose of $headers array ?
CLI shows me only the data from the database
maybe you have dd() somewhere?
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报