Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Class 'App\Http\Controllers\DownstreamResponse' not found #6

Closed
tarhe opened this issue Jul 17, 2016 · 8 comments
Closed

Class 'App\Http\Controllers\DownstreamResponse' not found #6

tarhe opened this issue Jul 17, 2016 · 8 comments

Comments

@tarhe
Copy link

tarhe commented Jul 17, 2016

Trying to send a Notification and I got the above error, how do I fix this?

@brozot
Copy link
Owner

brozot commented Jul 17, 2016

Hi
I think it Missing an import of Laravel-FCM\Response\DownstreamResponse somewhere in the code.

Can you give me more informations about this error.
Maybe with a part of your code that thrown the exception.

Thanks

@tarhe
Copy link
Author

tarhe commented Jul 17, 2016

$downstreamResponse = FCM::sendTo($tokens, $option, $notification);

$downstreamResponse->numberSuccess();
$downstreamResponse->numberFailure();
$downstreamResponse->numberModification();

//return Array - you must remove all this tokens in your database
$downstreamResponse->tokensToDelete();

//return Array (key : oldToken, value : new token - you must change the token in your database )
$downstreamResponse->tokensToModify();

//return Array - you should try to resend the message to the tokens in the array
$downstreamResponse->tokensToRetry();

// return Array (key:token, value:errror) - in production you should remove from your database the tokens present in this array
$downstreamResponse->tokensWithError();

@tarhe
Copy link
Author

tarhe commented Jul 17, 2016

I commented out those lines apart from the first one and it worked.

@brozot
Copy link
Owner

brozot commented Jul 17, 2016

I am unable to reproduce your problem

Do you use Laravel or Lumen?
Can you give me all the content of the error message?

@gcphost
Copy link
Contributor

gcphost commented Jul 18, 2016

This is related to not having the use statement for LaravelFCM\Response\DownstreamResponse (as you said, not imported).

The readme is missing them in some of the other examples, I only updated one.

@tarhe
Copy link
Author

tarhe commented Jul 22, 2016

I am using Laravel 5.2

Notifications are sent but it produce errors on my laravel.log and I found these lines of codes are the ones causing it:

        $downstreamResponse = new DownstreamResponse($response, $tokens);
        $downstreamResponse->numberSuccess();
        $downstreamResponse->numberFailure();
        $downstreamResponse->numberModification();

        //return Array - you must remove all this tokens in your database
        $downstreamResponse->tokensToDelete(); 

        //return Array (key : oldToken, value : new token - you must change the token in your database )
        $downstreamResponse->tokensToModify(); 

        //return Array - you should try to resend the message to the tokens in the array
        $downstreamResponse->tokensToRetry();

This was the error:

[2016-07-22 09:10:28] local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Api\V1\Controllers\DownstreamResponse' not found' in C:\wamp\www\MyApp\app\Api\V1\Controllers\PushNotificationController.php:42

After I did what @gcphost recommended (use LaravelFCM\Response\DownstreamResponse;), I got the following error:

[2016-07-22 09:11:39] local.ERROR: exception 'ErrorException' with message 'Undefined variable: response' in C:\wamp\www\MyApp\app\Api\V1\Controllers\PushNotificationController.php:42

Sorry, what does those lines of code do, I mean what are their functions.

@brozot
Copy link
Owner

brozot commented Jul 22, 2016

Hi,

I think that your error is thrown by the following line:

$downstreamResponse = new DownstreamResponse($response, $tokens); 

You shouldn't instantiate DownstreamReponse in your controller.

DownstreamResponse is constructed by the package and is returned by the method: FCM::sendTo($tokens, $option, $notification);

Like in the following line:

$downstreamResponse = FCM::sendTo($tokens, $option, $notification);

In summary,

  1. You send a notification with the method FCM::sendTo($tokens, $option, $notification);.
  2. The package is sending the notification and constructs a DownstreamResponse with the response returned by fcm.
  3. In your controller, you can check if the notification was send with success or if some error appeared during the process, with the following methods:
    $downstreamResponse->numberSuccess(), $downstreamResponse->numberFailure(); and $downstreamResponse->numberModification();
  4. You can get all tokens that you must to remove in your database with the method: $downstreamResponse->tokensToDelete();
  5. You can get all tokens that you must to modify in your database with the method: $downstreamResponse->tokensToModify();
  6. You can all tokens that you should resend with this method: $downstreamResponse->tokensToRetry();

Please can you give me a feedback if this solution is working for you.

Best Regards

@tarhe
Copy link
Author

tarhe commented Jul 26, 2016

Thanks for the detailed explanation, it works well now. Thanks

@tarhe tarhe closed this as completed Jul 26, 2016
actmkan pushed a commit to actmkan/Laravel-FCM that referenced this issue Mar 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants