Skip to content

Commit

Permalink
Created order delivered notification for the user who created the order
Browse files Browse the repository at this point in the history
  • Loading branch information
Raccoon254 committed Jun 21, 2024
1 parent 3837f98 commit dabcce4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Livewire/OrderDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Order;
use App\Models\Delivery;
use App\Models\DeliveryAttachment;
use App\Notifications\OrderDelivered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
Expand Down Expand Up @@ -52,6 +53,9 @@ public function saveDelivery(): RedirectResponse | Redirect | Redirector
]);
}

// Notify the user that their order has been delivered
$this->order->user->notify(new OrderDelivered($this->order));

session()->flash('success', 'Delivery created successfully.');

return redirect()->route('orders.show', $this->order);
Expand Down
54 changes: 54 additions & 0 deletions app/Notifications/OrderDelivered.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class OrderDelivered 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 [
//
];
}
}

0 comments on commit dabcce4

Please sign in to comment.