-
Notifications
You must be signed in to change notification settings - Fork 410
Added event support #100
base: master
Are you sure you want to change the base?
Added event support #100
Conversation
Writing event-based code is a lot better especially in big project because you can write all the logic of token update/create/delete in one place and don't repeat it everywhere but just do what the function is supposed to do. A short example of a real listener: <?php
namespace App\Listeners;
use App\Device;
use App\DeviceRegistrationRequest;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use LaravelFCM\Events\UpdateToken;
class UpdateFCMTokenListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UpdateToken $event
* @return void
*/
public function handle(UpdateToken $event)
{
$devices = Device::where('fcm_token',$event->originalToken)->get();
foreach($devices AS $device){
/**@var \App\Device $device**/
$device->update(['fcm_token'=>$event->newToken]);
}
$requests = DeviceRegistrationRequest::where('fcm_token',$event->originalToken)->get();
foreach($requests AS $request){
/**@var \App\DeviceRegistrationRequest $request**/
$request->update(['fcm_token'=>$event->newToken]);
}
}
} |
You have mixed tabs and spaces, messy syntax (spaces around operators are missing in some spots). Needs cleanup. Please try to copy the syntax the project already uses. |
@francislavoie no worries, in the time it took to have at least a reply from someone to my fixes i already implemented the FCM v1 API AND Firebase database API from scratch, including a Laravel package that uses it... |
Hi ! This is a fork that will be maintained as long as possible by @code-lts members 💪 🚀 1.4.0 was released See how to install it ( |
Added Laravel event triggering to handle FCM response events.
Due to non-uniformed response pattern only sendTo method will trigger those events but can be easly exended ( see LaravelFCM\Sender\FCMSender\dispatchEvents method implementation)