Skip to content

Commit

Permalink
Complete create Order notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed Jun 17, 2024
1 parent ae36d0d commit 2abfc1c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
24 changes: 17 additions & 7 deletions app/Notifications/OrderCreatedForUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Notifications;

use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
Expand All @@ -10,15 +11,15 @@
class OrderCreatedForUser extends Notification
{
use Queueable;
public Order $order;

/**
* Create a new notification instance.
*/
public function __construct()
public function __construct(Order $order)
{
//
$this->order = $order;
}

/**
* Get the notification's delivery channels.
*
Expand All @@ -35,9 +36,15 @@ public function via(object $notifiable): array
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!');
->greeting('Hello ' . $notifiable->name . ',')
->line('Your order has been successfully created.')
->line('Order Details:')
->line('Title: ' . $this->order->title)
->line('Description: ' . $this->order->description)
->line('Total Price: ' . $this->order->total_price)
->line('Status: ' . $this->order->status)
->action('View Order', url('/orders/' . $this->order->id))
->line('Thank you for using our service!');
}

/**
Expand All @@ -48,7 +55,10 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
//
'order_id' => $this->order->id,
'title' => $this->order->title,
'description' => $this->order->description,
'total_price' => $this->order->total_price,
];
}
}
24 changes: 18 additions & 6 deletions app/Notifications/OrderCreatedForWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Models\Order;

class OrderCreatedForWriter extends Notification
{
use Queueable;
public Order $order;

/**
* Create a new notification instance.
*/
public function __construct()
public function __construct(Order $order)
{
//
$this->order = $order;
}

/**
Expand All @@ -35,9 +37,15 @@ public function via(object $notifiable): array
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!');
->greeting('Hello ' . $notifiable->name . ',')
->line('A new order has been created by ' . $this->order->user->name)
->line('Order Details:')
->line('Title: ' . $this->order->title)
->line('Description: ' . $this->order->description)
->line('Total Price: ' . $this->order->total_price)
->line('Status: ' . $this->order->status)
->action('View Order', url('/orders/' . $this->order->id))
->line('Please review the order and proceed accordingly.');
}

/**
Expand All @@ -48,7 +56,11 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
//
'order_id' => $this->order->id,
'title' => $this->order->title,
'description' => $this->order->description,
'total_price' => $this->order->total_price,
'status' => $this->order->status,
];
}
}

0 comments on commit 2abfc1c

Please sign in to comment.