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

Laravel

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

Description

新しい通知クラスの作成

Usage

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

Arguments

引数必須設営
name必須通知クラス名

Options

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

Examples

no options

php artisan make:notification Foo
   INFO  Notification [app/Notifications/Foo.php] created successfully.  
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class Foo extends Notification
{
    use Queueable;

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

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            //
        ];
    }
}

Follow me!

コメント

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