Closed ljanecek closed 1 year ago
This would be useful when trying to use generateToken
to associate a user device with his own user id and/or deleteUser
.
Simply exposing the $beamsClient
should be enough, I can create a PR if you're open to it.
Simple. Dependency injection.
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use Pusher\PushNotifications\PushNotifications;
class BeamsController extends Controller
{
protected $beamsClient;
public function __construct(PushNotifications $beamsClient)
{
$this->middleware('auth');
$this->beamsClient = $beamsClient;
}
public function index()
{
$user = Auth::user();
$beamsToken = $this->beamsClient->generateToken('App.User.' . $user->id);
return response()->json($beamsToken);
}
}
@ljanecek How did you get it work? @geeksalah7 answer doesn't seem to work since PusherPushNotificationsServiceProvider lets only PusherChannel::class get injected with PushNotifications::class? Is there a way to get the beams instance without having to patch the property from protected to public?
@hypnocill rewrite the service provider to this.
/**
* Bootstrap the application services.
*/
public function register()
{
$this->app->when(PusherChannel::class)
->needs(PushNotifications::class);
$this->app->bind(PushNotifications::class, function ($app) {
$config = $app['config']['services']['pusher'];
return new PushNotifications([
'instanceId' => $config['instance_id'],
'secretKey' => $config['secret_key'],
]);
});
}
I would like to ask you, how right get beamsClient in route for generating token.
At this moment, my implementation looks like this:
I think, that Pusher\PushNotifications\PushNotifications should be registered in the Service provider to get instance with configurations. But, there is just booting. But, I'm not sure how exactly the Service provider in Laravel works.
Thanks!