Skip to content

Commit ac89359

Browse files
committed
Default subject based on mail class
1 parent 2f3e81a commit ac89359

File tree

8 files changed

+18
-6
lines changed

8 files changed

+18
-6
lines changed

src/Generators/Statements/MailGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function populateStub(string $stub, SendStatement $sendStatement)
6969
{
7070
$stub = str_replace('{{ namespace }}', config('blueprint.namespace') . '\\Mail', $stub);
7171
$stub = str_replace('{{ class }}', $sendStatement->mail(), $stub);
72+
$stub = str_replace('{{ subject }}', $sendStatement->subject(), $stub);
7273
$stub = str_replace('{{ view }}', $sendStatement->view(), $stub);
7374
$stub = str_replace('{{ properties }}', $this->populateConstructor('message', $sendStatement), $stub);
7475

src/Models/Statements/SendStatement.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,24 @@ class SendStatement
3737
*/
3838
private $view;
3939

40+
/**
41+
* @var string
42+
*/
43+
private $subject;
44+
4045
public function __construct(string $mail, ?string $to, array $data, string $type, string $view = null)
4146
{
4247
$this->mail = $mail;
4348
$this->data = $data;
4449
$this->to = $to;
4550
$this->type = $type;
4651
$this->view = $view ?? 'emails.' . Str::kebab($this->mail);
52+
$this->subject = $type === self::TYPE_MAIL ? Str::headline($this->mail) : '';
53+
}
54+
55+
public function subject(): string
56+
{
57+
return $this->subject;
4758
}
4859

4960
public function mail()

stubs/mail.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class {{ class }} extends Mailable
2121
public function envelope(): Envelope
2222
{
2323
return new Envelope(
24-
subject: '',
24+
subject: '{{ subject }}',
2525
);
2626
}
2727

tests/fixtures/mailables/added-admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct($user)
2929
public function envelope(): Envelope
3030
{
3131
return new Envelope(
32-
subject: '',
32+
subject: 'Added Admin',
3333
);
3434
}
3535

tests/fixtures/mailables/mail-configured.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct($post)
2929
public function envelope(): Envelope
3030
{
3131
return new Envelope(
32-
subject: '',
32+
subject: 'Review Post',
3333
);
3434
}
3535

tests/fixtures/mailables/published-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct()
2727
public function envelope(): Envelope
2828
{
2929
return new Envelope(
30-
subject: '',
30+
subject: 'Published Post',
3131
);
3232
}
3333

tests/fixtures/mailables/return-type-declarations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct($post)
2929
public function envelope(): Envelope
3030
{
3131
return new Envelope(
32-
subject: '',
32+
subject: 'Review Post',
3333
);
3434
}
3535

tests/fixtures/mailables/review-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct($post)
2929
public function envelope(): Envelope
3030
{
3131
return new Envelope(
32-
subject: '',
32+
subject: 'Review Post',
3333
);
3434
}
3535

0 commit comments

Comments
 (0)