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

476
Views
laravel: no se pueden pasar parámetros al rasgo

Creé un rasgo en MailTrait.php, el siguiente es mi código

 namespace App\Traits; use Mail; trait MailTrait { public function fn_send_mail($arr_recepients, $str_subject, $str_content) { Mail::send('mail.mailsample', ['content' => $str_content], function($message) { $message->to($arr_recepients); $message->from('abc.org', 'abc'); $message->subject($str_subject); }); if(Mail:: failures()) return false; else return true; } }

desde mi controlador llamó a la función fn_send_mail() y pasó el parámetro como se muestra a continuación $status = $this->fn_send_mail(['123.gmail.com'],'hai', 'hai');

Recibo este error ErrorException in MailTrait.php line 14: Undefined variable: arr_recepients , ¡por favor ayúdenme!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Debe pasar $arr_recepients al bloque de devolución de llamada

 Mail::send('mail.mailsample', ['content' => $str_content], function($message) use ($arr_recepients, $str_subject) { $message->to($arr_recepients); $message->from('abc.org', 'abc'); $message->subject($str_subject); });
over 4 years ago · Santiago Trujillo Report

0

El tercer argumento de Mail::send es un cierre, y no tiene $arr_recepients en el alcance, ni el asunto. Necesitas usar el use . Prueba esto

 Mail::send('mail.mailsample', ['content' => $str_content], function($message) use ($arr_recepients, $str_subject) { //...
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!