diff --git a/app/Http/Controllers/PostPublishController.php b/app/Http/Controllers/PostPublishController.php new file mode 100644 index 0000000..84a2a63 --- /dev/null +++ b/app/Http/Controllers/PostPublishController.php @@ -0,0 +1,16 @@ +render(); + } +} diff --git a/app/Mail/PostPublished.php b/app/Mail/PostPublished.php index f6789dc..a0fd349 100644 --- a/app/Mail/PostPublished.php +++ b/app/Mail/PostPublished.php @@ -2,6 +2,7 @@ namespace App\Mail; +use App\Models\Post; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Mail\Mailable; @@ -13,14 +14,16 @@ class PostPublished extends Mailable { use Queueable, SerializesModels; + public Post $post; + /** * Create a new message instance. * * @return void */ - public function __construct() + public function __construct(Post $post) { - // + $this->post = $post; } /** @@ -44,6 +47,9 @@ public function content() { return new Content( markdown: 'emails.posts.published', + with: [ + 'url' => url("/posts/{$this->post->id}"), + ], ); } diff --git a/resources/views/emails/posts/published.blade.php b/resources/views/emails/posts/published.blade.php index de9a155..288921a 100644 --- a/resources/views/emails/posts/published.blade.php +++ b/resources/views/emails/posts/published.blade.php @@ -1,10 +1,10 @@ -# Introduction +# Post Published -The body of your message. +Your post has been published on Medium - -Button Text + +View Post Thanks,
diff --git a/routes/web.php b/routes/web.php index af20c2d..d2dd552 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ use App\Http\Controllers\HomeController; use App\Http\Controllers\MediaUploaderController; use App\Http\Controllers\PostController; +use App\Http\Controllers\PostPublishController; use Illuminate\Support\Facades\Route; /* @@ -56,4 +57,9 @@ Route::get('/upload/download/{filename}', 'download')->name('upload.download'); }); + + Route::prefix('mailable')->group(function() { + Route::get('template/{id}', [PostPublishController::class, 'previewMailTemplate']) + ->name('mailable.preview'); + }); }); diff --git a/tests/Feature/MailTest.php b/tests/Feature/MailTest.php index 1a4a1da..c80a3f0 100644 --- a/tests/Feature/MailTest.php +++ b/tests/Feature/MailTest.php @@ -4,6 +4,8 @@ use App\Mail\OrderShipped; use App\Mail\PostPublished; +use App\Models\Post; +use App\Models\User; use Illuminate\Contracts\Mail\Mailable; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; @@ -11,13 +13,30 @@ class MailTest extends TestCase { + use RefreshDatabase; + /** @test */ public function mailables_are_available() { - $postPublished = new PostPublished(); + $this->actingAs($user = User::factory()->create()); + + $post = Post::factory()->create(['user_id' => $user->id]); + + $postPublished = new PostPublished($post); $orderShipped = new OrderShipped(); $this->assertInstanceOf(Mailable::class, $postPublished); $this->assertInstanceOf(Mailable::class, $orderShipped); } + + /** @test */ + public function mailable_can_be_previewed() + { + $this->actingAs($user = User::factory()->create()); + + $post = Post::factory()->create(['user_id' => $user->id]); + + $this->get(route('mailable.preview', $post->id)) + ->assertStatus(200); + } }