-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test mailable can have attachments at runtime
Unclexo
- Loading branch information
Showing
11 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class OrderController extends Controller | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Mail\PostPublished; | ||
use App\Models\Post; | ||
|
||
class PostPublishController extends Controller | ||
{ | ||
public function previewMailTemplate(int $id) | ||
{ | ||
$post = Post::find($id); | ||
|
||
return (new PostPublished($post))->render(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\Order; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Attachment; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class OrderShipped extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public Order $order; | ||
|
||
/** | ||
* Create a new message instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Order $order) | ||
{ | ||
$this->order = $order; | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
* | ||
* @return \Illuminate\Mail\Mailables\Content | ||
*/ | ||
public function content() | ||
{ | ||
return new Content( | ||
markdown: 'emails.orders.shipped', | ||
with: [ | ||
'url' => url("/orders/{$this->order->id}"), | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Get the attachments for the message. | ||
* | ||
* @return array | ||
*/ | ||
public function attachments() | ||
{ | ||
return [ | ||
Attachment::fromPath(storage_path('app/public/some.pdf')), | ||
Attachment::fromStorageDisk('public', 'other.pdf'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace App\Mail; | ||
|
||
use App\Models\Post; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Address; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class PostPublished extends Mailable | ||
{ | ||
use Queueable, SerializesModels; | ||
|
||
public Post $post; | ||
|
||
/** | ||
* Create a new message instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Post $post) | ||
{ | ||
$this->post = $post; | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
* | ||
* @return \Illuminate\Mail\Mailables\Envelope | ||
*/ | ||
public function envelope() | ||
{ | ||
return new Envelope( | ||
from: new Address('[email protected]', 'Medium Online Publication'), | ||
to: new Address('[email protected]', 'Abu Jobaer'), | ||
bcc: new Address('[email protected]', 'Ria Jobaer'), | ||
replyTo: [ | ||
new Address('[email protected]', 'Taylor Otwell'), | ||
], | ||
subject: 'Post Published', | ||
tags: ['architecture', 'design-patterns'], | ||
metadata: [ | ||
'post_id' => $this->post->id, | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
* | ||
* @return \Illuminate\Mail\Mailables\Content | ||
*/ | ||
public function content() | ||
{ | ||
return new Content( | ||
markdown: 'emails.posts.published', | ||
with: [ | ||
'url' => url("/posts/{$this->post->id}"), | ||
], | ||
); | ||
} | ||
|
||
/** | ||
* Get the attachments for the message. | ||
* | ||
* @return array | ||
*/ | ||
public function attachments() | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Order extends Model | ||
{ | ||
use HasFactory; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Order> | ||
*/ | ||
class OrderFactory extends Factory | ||
{ | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'user_id' => User::factory()->create(), | ||
'shipper_id' => $this->faker->numberBetween(1, 10), | ||
'name' => $this->faker->userName, | ||
'price' => $this->faker->numberBetween(100, 10000), | ||
]; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
database/migrations/2023_01_06_152053_create_orders_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('orders', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('user_id'); | ||
$table->unsignedBigInteger('shipper_id'); | ||
$table->string('name'); | ||
$table->unsignedDecimal('price'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('orders'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<x-mail::message> | ||
# Order Shipped | ||
|
||
Your order has been shipped. The order summary: | ||
|
||
Order ID: {{ $order->id }} | ||
Name: {{ $order->name }} | ||
Price: {{ $order->price }} | ||
|
||
<x-mail::button :url="$url"> | ||
View Order | ||
</x-mail::button> | ||
|
||
Thanks,<br> | ||
{{ config('app.name') }} | ||
</x-mail::message> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<x-mail::message> | ||
# Post Published | ||
|
||
Your post has been published on Medium | ||
|
||
<x-mail::button :url="$url"> | ||
View Post | ||
</x-mail::button> | ||
|
||
Thanks,<br> | ||
{{ config('app.name') }} | ||
</x-mail::message> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.