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

484
Visualizações
laravel : Not able to pass parameters to trait

I created a trait in MailTrait.php, the following is my code

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;
    }

}

from my controller called the function fn_send_mail() and passed parameter as below $status = $this->fn_send_mail(['123.gmail.com'],'hai', 'hai');

i am getting this error ErrorException in MailTrait.php line 14: Undefined variable: arr_recepients please help me!!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You should pass the $arr_recepients to the callback-block

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 Relatório

0

The 3rd argument to Mail::send is a closure, and it doesn't have $arr_recepients in scope, nor the subject. You need to use the use. Try this

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