Php 使用laravel excel从数据库导出大型数据?

Php 使用laravel excel从数据库导出大型数据?,php,laravel,laravel-excel,Php,Laravel,Laravel Excel,我正在使用软件包,我在DB中有30000多个产品,我需要将数据排队,然后将最终文件发送到电子邮件,通知用户该文件已准备好从电子邮件下载 录制到: 排队完成后,有没有办法将文件发送到电子邮件?遵循以下结构: 在您的ExportProducts类中,确保实现ShouldQueue 在控制器中,控制器可能是这样的: <?php namespace App\Http\Controllers; use App\Exports\ExportProducts; use App\Http\Cont

我正在使用软件包,我在
DB
中有30000多个产品,我需要将数据排队,然后将最终文件发送到电子邮件,通知用户该文件已准备好从电子邮件下载

录制到:

排队完成后,有没有办法将文件发送到电子邮件?

遵循以下结构:

  • 在您的
    ExportProducts
    类中,确保
    实现ShouldQueue

  • 在控制器中,控制器可能是这样的:

    <?php 
    
    namespace App\Http\Controllers;
    
    use App\Exports\ExportProducts;
    use App\Http\Controllers\Controller;
    use App\Jobs\Export\NotifyMerchantOfCompleteFileExport;
    
    class FooController extends Controller
    {
        public function index()
        {
            $fileName = 'uploads/excel-files/'.Str::random(3).'.xlsx';
            $filePath = asset($fileName);
    
            (new ExportProducts)->store($fileName,'public')->chain([
                new NotifyUserOfCompleteFileExport(auth()->user(),$filePath),
            ]);;
    
            return back()->withSuccess('export started'));
        }
    }
    
  • 创建新的电子邮件文件
    CompleteExportedFile

    <?php
    
    namespace App\Mail;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Mail\Mailable;
    use Illuminate\Queue\SerializesModels;
    
    class CompleteExportedFile extends Mailable implements ShouldQueue
    {
        use Queueable, SerializesModels;
    
        public $filePath;
    
        public function __construct($filePath)
        {
            $this->filePath  = $filePath;
        }
    
        public function build()
        {
            return $this->subject('File has been exported')
                    ->markdown('emails.send-export-file');
        }
    }
    
    希望有用:)

    <?php
    
    namespace App\Jobs;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Support\Facades\Mail;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Queue\InteractsWithQueue;
    use App\Mail\Merchant\CompleteExportedFile;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Foundation\Bus\Dispatchable;
    
    class NotifyUserOfCompleteFileExport implements ShouldQueue
    {
        use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
        public $user;
        public $filePath;
    
        public function __construct($user,$filePath)
        {
            $this->user = $user;
            $this->filePath = $filePath;
        }
    
        public function handle()
        {
            Mail::to($this->user)->send(new CompleteExportedFile($this->filePath));
        }
    }
    
    <?php
    
    namespace App\Mail;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Mail\Mailable;
    use Illuminate\Queue\SerializesModels;
    
    class CompleteExportedFile extends Mailable implements ShouldQueue
    {
        use Queueable, SerializesModels;
    
        public $filePath;
    
        public function __construct($filePath)
        {
            $this->filePath  = $filePath;
        }
    
        public function build()
        {
            return $this->subject('File has been exported')
                    ->markdown('emails.send-export-file');
        }
    }
    
    <a href="{{ $filePath }}" download="download" class="button button-success" target="_blank" rel="noopener">@lang('site.donwload_file')</a>