Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Sep 7, 2019 · 2 comments
Labels

Comments

@samiaMH
Copy link

samiaMH commented Sep 7, 2019

//////////////////// 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
Copy link
Collaborator

erlangparasu commented Sep 9, 2019

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
Copy link
Collaborator

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants