SendMessage.php 1.51 KB
<?php

namespace App\Mail;

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

class SendMessage extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    public $messageText;
    public $userName;
    public $link;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($message,$user)
    {

        $this->messageText = $message->text;
        $this->userName = $user->name;
        $this->link = route('employer.dialog', ['chat' => $message->chat_id_from]);

    }

    /**
     * Get the message envelope.
     *
     * @return \Illuminate\Mail\Mailables\Envelope
     */
    public function envelope()
    {
        return new Envelope(
            subject: 'У вас новое личное сообщение!',
        );
    }

    /**
     * Get the message content definition.
     *
     * @return \Illuminate\Mail\Mailables\Content
     */
    public function content()
    {

        return new Content(
            view: 'emails.message',
            with: [
              'text' => $this->messageText,
              'userName' => $this->userName,
              'link' => $this->link,
          ],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array
     */
    public function attachments()
    {
        return [];
    }
}