swimmer
4 months ago
394
2
Laravel

Issue with pathing variable to email template

Posted 4 months ago by swimmer

I am trying to create an email template I have a method That passes the following

 $to = '[email protected]';
 $item_status = array('success'=>$counter_success,'failure'=>$counter_failure,'warning'=>$counter_warning);
 $site = 'tradesy';

  $mail = new MailController();
  $mail->sendMail($to,$item_status,$site);

My controller is

<?php
    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\Mail;
    use App\Mail\TestMail;
    class MailController extends Controller
    {
        /**
         * Send mail function
         *
         */
        public function sendMail($to,$item_status,$site)
        {
            Mail::to($to)
                
                ->send(new TestMail($item_status,$site));
            
            if (Mail::failures()) {
                // return with failed message
            }
            // return with success message
        }
    }


And my Mailable is


<?php

my app is


namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    public $item_status;
    public $site;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($item_status,$site)
    {
        $this->item_status = $item_status;
        $this->site = $site;

    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this
                ->from('[email protected]') // Sender mail
                ->subject('Test Subject') // Mail subject                
                ->view('mail',$item_status,$site); // View file resource/views/mail/index
                
    }
}


I’m not able to pass the ,$item_status info to my template.

What am I doing wrong?

Please sign in or create an account to participate in this conversation.