【Laravel】artisanのmake:mailコマンドを解説

Laravel

Laravel 10.xのartisanの「make:mail」コマンドを解説します。

Description

新しいEメールクラスの作成

Usage

php artisan make:mail [-f|--force] [-m|--markdown [MARKDOWN]] [--test] [--pest] [--] <name>

Arguments

引数必須設営
name必須Eメールクラス名

Options

オプション省略形必須説明
forcef-Eメールクラスが既に存在する場合でもクラスを作成
markdownm-Eメールクラス用のMarkdownテンプレートを新規作成
test--Eメールクラスに付随するPHPUnitテストを生成
pest--Mailableの付属のPestテストを生成します。

Examples

no options

php artisan make:mail Foo
   INFO  Mailable [app/Mail/Foo.php] created successfully.  
<?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 Foo extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Foo',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'view.name',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}

Follow me!

コメント

PAGE TOP
タイトルとURLをコピーしました