dev-master
9999999-devThis library provides Server Sent Event for Laravel.
MIT
The Requires
by Alban Afmeti
Wallogit.com
2017 © Pedro Peláez
This library provides Server Sent Event for Laravel.
This library provides Server Sent Event for Laravel. Tested on Laravel 5.5., (*1)
This package is installed via Composer. To install, simply add it
to your composer.json file:, (*2)
{
"require": {
"noisim/ss-event": "dev-master"
}
}
and run composer to update the dependencies composer update., (*3)
Then open your Laravel config file config/app.php and in the $providers array add the service provider for this package., (*4)
\Noisim\SSEvent\SSEventServiceProvider::class
Finally generate the configuration file running in the console:, (*5)
php artisan vendor:publish --tag=config
Laravel Controller:, (*6)
<?php
namespace App\Http\Controllers;
use Noisim\SSEvent\SSEvent;
class TestController extends Controller
{
public function test()
{
$sse = new SSEvent();
return $sse->sleepTime(10)->addEvent("event_name", function () {
return json_encode(["hello" => "world"]);
})->start();
}
}
Laravel Route:, (*7)
<?php
Route::get('test', 'TestController@test')->name("test");
Client Javascript:, (*8)
var source = new EventSource('/test'); source.addEventListener('event_name', function(event) { console.log(event); }, false);
This library provides Server Sent Event for Laravel.
MIT