Laravel 10.xのartisanの「make:notification」コマンドを解説します。
Description
新しい通知クラスを作成します。
Usage
php artisan make:notification [-f|--force] [-m|--markdown [MARKDOWN]] [--test] [--pest] [--] <name>
Arguments
引数 | 必須 | 設営 |
---|---|---|
name | 必須 | 通知クラス名 |
Options
オプション | 省略形 | 必須 | 説明 |
---|---|---|---|
force | f | - | 通知クラスが既に存在する場合でも、クラスを作成 |
markdown | m | - | 通知用の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 [
//
];
}
}
Stub
Option | Stub file name |
---|---|
- | notification.stub |
markdown | markdown-notification.stub |
Source
10.x
framework/src/Illuminate/Foundation/Console/NotificationMakeCommand.php at 10.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
11.x
framework/src/Illuminate/Foundation/Console/NotificationMakeCommand.php at 11.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
コメント