Я хочу отправить несколько уведомлений.Таким образом, я отправляю уведомление, что
у вас есть событие на этой неделе
, но я хочу, если есть несколько событий, чем уведомление будет отображаться так
на этой неделе у вас будет пара событий
Как я могу это сделать.Пожалуйста, помогите мне.
Вот код моего контроллера:
public function upcomingWeekEvent()
{
$datatime = new DateTime(); // getting current date and time
$currentDatetime = $datatime->format('Y-m-d');
$datatime->add(new DateInterval('P1W')); // getting 1 week after of current time period
$afterWeekDatetime = $datatime->format('Y-m-d');
$events = Activity::where('activity_type', 'event')
->whereBetween('activity_datetime_from', [$currentDatetime, $afterWeekDatetime])->get();
// dd($events);
foreach ($events as $event) {
$user = $event->user;
$push = new PushNotification('apn');
$push->setMessage([
'aps' => [
'alert' => ' You have an event coming up this week',
'sound' => 'default',
'badge' => $user->unreadNotifications->count()
],
'extraPayLoad' => [
// 'user' => $authUser,
'event' => $event->id,
'activity_type' => $event->activity_type,
'notification_type' => "UpcomingWeekEvent",
]
]);
$tokens = $user->deviceTokens()->pluck('deviceToken')->toArray();
$push->setDevicesToken($tokens);
$push->send();
$feedback = $push->getFeedback();
$user->notify(new UpcomingWeekEvent($event));
}
return response()->json(['aasa'=>$events]);
// return response()->json(['currentDatetime'=> $currentDatetime, 'afterWeekDatetime'=> $afterWeekDatetime, 'result'=> $events], 200);
}
В этом коде он отправляет только одно уведомление
У вас есть событие, подходящеена этой неделе
Но в событиях, если в нем несколько событий, чем я хочу отправить это уведомление
, у вас есть пара событий на этой неделе
Вот код уведомления о предстоящем WeekEvents.php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class UpcomingWeekEvent extends Notification
{
use Queueable;
protected $event;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($event)
{
$this->event = $event;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the database representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'activity_id' => $this->event->id,
'notification' => 'You have an event coming up this week',
'icon_type' => $this->event->activity_type,
];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}