Laravel - Responses - Streamed Downloads

Sometimes you may wish to turn the string response of a given operation into a downloadable response without having to write the contents of the operation to disk. You may use the streamDownload method in this scenario. This method accepts a callback, filename, and an optional array of headers as its arguments:

    use App\Services\GitHub;
    return response()->streamDownload(function () {
        echo GitHub::api('repo')
                    ->readme('laravel', 'laravel')['contents'];
    }, '');