<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: laravel developer</title>
    <description>The latest articles on DEV Community by laravel developer (@laravel_developer_5edfed8).</description>
    <link>https://dev.to/laravel_developer_5edfed8</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3275477%2Fa1698285-dfea-4100-96a6-6d5ca2189411.png</url>
      <title>DEV Community: laravel developer</title>
      <link>https://dev.to/laravel_developer_5edfed8</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/laravel_developer_5edfed8"/>
    <language>en</language>
    <item>
      <title>100m download csv</title>
      <dc:creator>laravel developer</dc:creator>
      <pubDate>Thu, 24 Jul 2025 04:55:39 +0000</pubDate>
      <link>https://dev.to/laravel_developer_5edfed8/100m-download-csv-5e96</link>
      <guid>https://dev.to/laravel_developer_5edfed8/100m-download-csv-5e96</guid>
      <description>&lt;p&gt;public function export(Request $request)&lt;br&gt;
    {&lt;br&gt;
        $businessId = $request-&amp;gt;input('business_id'); // Optional filter&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    return Excel::download(new PurchasedNotificationPackagesExport($businessId),'PurchasedPackages.xlsx');
}

public function export()
{
    $response = new StreamedResponse(function () {
        $handle = fopen('php://output', 'w');

        // Header row
        fputcsv($handle, [
            'Business Name',
            'Package Name',
            'Total Push Limit',
            'Push Limit (Left)',
            'Start Datetime',
            'End Datetime',
            'Days (Left)',
            'Price',
            'Status',
        ]);

        // Fetch data in chunks
        PurchasedNotificationPackage::with(['business', 'notification_package'])
            -&amp;gt;selectRaw('*, DATEDIFF(end_datetime, ?) as remaining_days', [Carbon::now()-&amp;gt;toDateTimeString()])
            -&amp;gt;when(request('business_id'), fn($q) =&amp;gt; $q-&amp;gt;where('business_id', request('business_id')))
            -&amp;gt;latest()
            -&amp;gt;chunk(1000, function ($packages) use ($handle) {
                foreach ($packages as $row) {
                    $status = 'Inactive';
                    if (($row-&amp;gt;end_datetime &amp;amp;&amp;amp; Carbon::parse($row-&amp;gt;end_datetime)-&amp;gt;isPast()) || $row-&amp;gt;push_limit == 0) {
                        $status = 'Expired';
                    } elseif ($row-&amp;gt;status == '1') {
                        $status = 'Active';
                    }

                    $start = Carbon::parse($row-&amp;gt;start_datetime)-&amp;gt;format(config('app.app_datetime_without_seconds_format'));
                    $end = Carbon::parse($row-&amp;gt;end_datetime)-&amp;gt;format(config('app.app_datetime_without_seconds_format'));

                    fputcsv($handle, [
                        $row-&amp;gt;business-&amp;gt;name ?? 'N/A',
                        $row-&amp;gt;notification_package-&amp;gt;name ?? 'N/A',
                        $row-&amp;gt;purchased_push_limit == 0 ? '0' : $row-&amp;gt;purchased_push_limit,
                        $row-&amp;gt;push_limit == 0 ? '0' : $row-&amp;gt;push_limit,
                        $start,
                        $end,
                        $row-&amp;gt;remaining_days . ' days',
                        $row-&amp;gt;price,
                        $status,
                    ]);
                }
            });

        fclose($handle);
    });

    $response-&amp;gt;headers-&amp;gt;set('Content-Type', 'text/csv');
    $response-&amp;gt;headers-&amp;gt;set('Content-Disposition', 'attachment; filename="purchased_packages_' . now()-&amp;gt;format('Ymd_His') . '.csv"');

    return $response;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
  </channel>
</rss>
