我還假設您已經正確設置了您的Pusher帳戶,並且您的環境變量是正確的。
如果是這樣,您可能需要確保您使用的是正確的羣集(默認情況下適用於美國,但在美國東海岸以外,例如羣集必須明確定義)。
更新:
控制器代碼:
<?php
namespace App\Http\Controllers;
use Vinkla\Pusher\Facades\Pusher;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class TestPusherController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function test(){
$arr = array('test' => 'hello world 2') ;
$pusher = new Pusher(env('PUSHER_KEY'), env('PUSHER_SECRET'), env('PUSHER_APP_ID'), array('encrypted' => true, 'cluster' => 'ap1'));
$pusher::trigger('test_channel', 'my_event', $arr);
return $arr;
}
public function shortenedTest(){
$message = 'Hello world';
Pusher::trigger('my-channel', 'my-event', ['message' => $message]);
}
}
在網絡路線:
Route::get('testPusherController', '[email protected]');
Route::get('shortenedTestPusherController', '[email protected]');
我有一個新的這方面的工作按照https://github.com/vinkla/laravel-pusher的設置步驟vinkla /推杆的安裝,在Laravel 5.3上,使用內置的PHP服務器和連接到EU服務器(目前我沒有任何使用ap1的Pusher應用程序)。
您會注意到控制器中編碼的少量更改以獲取正確的格式。您必須在控制器上方使用Pusher外觀。
爲了完整起見,我添加了一個更好的工作方式,您可以在Config/pusher.php文件中設置Pusher憑證,而無需爲每次使用設置連接。這可以在控制器上的shortenedTest()方法中看到。
<?php
return [
'connections' => [
'main' => [
'auth_key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_CLUSTER')
],
'host' => null,
'port' => null,
'timeout' => null,
],
'alternative' => [
'auth_key' => 'your-auth-key',
'secret' => 'your-secret',
'app_id' => 'your-app-id',
'options' => [],
'host' => null,
'port' => null,
'timeout' => null,
],
],
];
您是否在https://dashboard.pusher.com/上的調試控制檯中看到了這些事件? –
不,我沒有看到任何事件 –
我還沒有在Laravel中使用這個,但是從我的閱讀中不應該使用'broadcast()'方法? https://laravel.com/docs/5.3/broadcasting#broadcasting-events –