Files
daily-meal-api/app/Notifications/MealPostCommentedNotification.php
T
leonm df4f523089
CI / 🧪 Tests Laravel (push) Successful in 2m7s
CI / 🐳 Build & Push Image (push) Successful in 42s
feat: add persistent mobile notifications
2026-08-11 16:46:05 +02:00

44 lines
1.3 KiB
PHP

<?php
namespace App\Notifications;
use App\Models\PostReviews;
use App\Services\MobileDeepLink;
use Illuminate\Support\Str;
class MealPostCommentedNotification extends MobileNotification
{
public function __construct(private readonly PostReviews $postReview)
{
parent::__construct();
}
protected function category(): string
{
return self::CATEGORY_SOCIAL;
}
protected function payload(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 [
'type' => 'meal_commented',
'title' => __('api.notifications.meal_post_commented_title'),
'body' => __('api.notifications.meal_post_commented_body', [
'meal' => $mealTitle,
'name' => $commenterName,
]),
'url' => MobileDeepLink::to("meals/{$mealPostId}"),
];
}
}