kawankoding / laravel-fcm

Firebase Cloud Messaging (FCM) sender for Laravel
172 stars 56 forks source link

I used this package but u dont know why its not sent a notification? it's give me a blank page ? #31

Open samiaMH opened 4 years ago

samiaMH commented 4 years ago

//////////////////// 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();
 }

} //////////////////// route ////////////////////

Route::get('/sendnotification','FcmController@sendnotification')->name('sendnotification');

erlangparasu commented 4 years ago

if you need to display the response, please use variable to get the response after calling send method, Eg.:

public function sendnotification()
{
    $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 Laravel
    return $responseArr; 
}
erlangparasu commented 1 year ago

@samiaMH .. also maybe you can try to enable debug response. then check the firebase log in the laravel.log file.

fcm()
    ->to($recipients)
    // ...
    ->enableResponseLog()
    ->send();

if you like, please share the response log here so we can see the problem