feat: notifications on comments
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\PostReviews;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MealPostCommentedNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(private readonly PostReviews $postReview) {}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['expo'];
|
||||
}
|
||||
|
||||
public function toExpoPush(object $notifiable): array
|
||||
{
|
||||
$this->postReview->loadMissing(
|
||||
'mealPost:id,title,user_id',
|
||||
'user:id,name',
|
||||
);
|
||||
|
||||
$mealPost = $this->postReview->mealPost;
|
||||
$mealPostId = $mealPost?->getKey() ?? $this->postReview->meal_post_id;
|
||||
$mealTitle = Str::limit((string) ($mealPost?->title ?: __('api.notifications.your_meal')), 60);
|
||||
$commenterName = $this->postReview->user?->name ?: __('api.notifications.someone');
|
||||
|
||||
return [
|
||||
'title' => __('api.notifications.meal_post_commented_title'),
|
||||
'body' => __('api.notifications.meal_post_commented_body', [
|
||||
'meal' => $mealTitle,
|
||||
'name' => $commenterName,
|
||||
]),
|
||||
'sound' => 'default',
|
||||
'channelId' => 'default',
|
||||
'data' => [
|
||||
'url' => "bowly://meals/{$mealPostId}",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user