Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

574
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda