Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

572
Visualizações
Size limit when passing a variable to Mail:send laravel

I'm trying to pass a query result into a view, but I keep getting an error: Maximum execution time of 30 seconds exceeded I'm passing smaller objects through and its working fine, but it breaks when I pass the result of $monthlyBidStatment through. If there is a better way of doing this I'd really appreciate any advice. Thanks in advance.

public function sendEmailInvoice(Request $request)
    {
        $invoice = Invoice::where('id', '=', $request->invoiceId)->first();
        $startDate = $invoice->start_billing_date;
        $startDateSql = date("Y-m-d", strtotime($startDate));
        $endDate = $invoice->end_billing_date;
        $endDateSql = date("Y-m-d", strtotime($endDate));
        $affiliate = AffiliateDetail::where('id', '=', $invoice->affiliate_detail_id)->first();
        $monthlyBidStatment = BidTracker::where('affiliate_detail_id', '=', $affiliate->id)->whereBetween('created_at', [$startDateSql, $endDateSql])->get();

        // LOG::info(gettype($monthlyBidStatment));

        Mail::send('pdf.invoicePDF', [
            'oAffiliate' => $affiliate,
            'oInvoice' => $invoice,
            'bids' => $monthlyBidStatment,
            'showBreadcrumb' => false
        ], function ($m) use ($affiliate, $invoice, $monthlyBidStatment)
        {
            $m->from(env('APP_EMAIL'), env('APP_NAME'));
            $m->to($affiliate->info_billing_email, $affiliate->info_company_name)->subject(env('APP_NAME') . ' Invoice');
            $pdf = PDF::loadView('pdf.invoicePDF', [
                'oAffiliate' => $affiliate,
                'oInvoice' => $invoice,
                'bids' => $monthlyBidStatment,
                'showBreadcrumb' => false
            ]);

            $m->attachData($pdf->output(), 'invoice.pdf');
        });

        $request->session()->flash('message', 'Successfully sent email invoice');
        return array(
            'status' => 'ok'
        );
    }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Check the following line:

$invoice = Invoice::where('id', '=', $request->invoiceId)->first();
// Its a collection object.

All multi-result sets returned by Eloquent are instances of the Illuminate\Database\Eloquent\Collection object, including results retrieved via the get method or accessed via a relationship. The Eloquent collection object extends the Laravel base collection, so it naturally inherits dozens of methods used to fluently work with the underlying array of Eloquent models.

In short terms we can say a collection object contains so many things in it, but in your case you only want the data part. So instead of passing the entire collection object, convert it into an array by iterating it with the required column and pass that array to email template. It will remove the overheads.

Ex:

$data = array();
$users = App\User::where('active', 1)->get();
foreach ($users as $user) {
    $data[] = $user->name;
}
// Use $data where required

Reference

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda