You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//////////////////// method in controller ////////////////////
public function sendnotification(){
$registrationIds= array();
$recipients = Fcm_info::select('token')->get();
for ($i = 0, $c = count($recipients); $i < $c; ++$i) {
array_push($registrationIds, $recipients[$i]['token']);
fcm()
->to($registrationIds) // $recipients must an array
->priority('normal')
->notification([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
])
->send();
}
if you need to display the response, please use variable to get the response after calling send method, Eg.:
publicfunctionsendnotification()
{
$registrationIds = Fcm_info::select(['token'])
->pluck('token')
->toArray();
$responseArr = fcm()
->to($registrationIds)
->priority('normal')
->timeToLive(0)
->notification([
'title' => 'Test FCM',
'body' => 'This is a test of FCM',
])
->send();
// The array will converted to response object automatically by Laravelreturn$responseArr;
}
//////////////////// method in controller ////////////////////
public function sendnotification(){
$registrationIds= array();
$recipients = Fcm_info::select('token')->get();
}
//////////////////// route ////////////////////
Route::get('/sendnotification','FcmController@sendnotification')->name('sendnotification');
The text was updated successfully, but these errors were encountered: