<?php

namespace App\Mail;

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

class VisitorMessagesMail extends Mailable
{
    use Queueable, SerializesModels;

    public $data;
    public $view;

    /**
     * Create a new message instance.
     *
     * @param $data
     * @param $view
     */
    public function __construct($data, $view)
    {
        $this->data = $data;
        $this->view = $view;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        // dd($this->data, $this->view);
        
        $mail= $this
        ->subject( $this->data['subject'])
        ->view($this->view, ['data'=> $this->data]);
        return $mail;
        return $this->view($this->view ?? 'admin.visitor_messages.email');
    }
}
