Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

568
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!