title: How can I use a resource to write line by line but still use Laravel's built in Storage?
body: <p>I want to use <code>Storage::put</code> to write a file.  The file is potentially very large (>100MB), so I want to utilise a stream so I don't blindly place everything into memory.</p>
  
  <p>I'm going to be making multiple API requests, and then looping through their results, so the data I'll be getting back isn't an issue, it'll be limited to sensible amounts.</p>
  
  <p>According to the <a href="https://laravel.com/docs/5.3/filesystem#storing-files" rel="nofollow noreferrer">documentation</a>, I need to use:</p>
  
  <pre><code>Storage::put('file.xml', $resource);
  </code></pre>
  
  <p>But what would <code>$resource</code> be here?  </p>
  
  <p>Traditionally when writing files using PHP I have done it with a combination of <code>fopen</code>, <code>fwrite</code> and <code>fclose</code> in order to write 'line by line'.  I'm building the file up by looping through various Collections and utlising various APIs as I go, so <code>$resource</code> is <em>NOT</em> a file pointer or file reference as is talked about elsewhere in the documentation.</p>
  
  <p>So, how can I write line by line using a stream and Laravel's <code>Storage</code>?</p>