我正在将BrainSocket与我的laravel应用程序集成。 BrainSocket需要添加以下两行:
require app_path().'/filters.php';
require app_path().'/events.php';
在app / start / global.php中。但我无法在我的laravel应用程序的app文件夹中找到该文件夹。如何将brainsocket与我的laravel 5应用程序集成?
答案 0 :(得分:0)
要使一些功能BrainSocket在Laravel 4中工作,请在events.php
Event::listen('generic.event',function($client_data){
return BrainSocket::message('generic.event',array('message'=>'A message from a generic event fired in Laravel!'));
});
Event::listen('app.success',function($client_data){
return BrainSocket::success(array('There was a Laravel App Success Event!'));
});
Event::listen('app.error',function($client_data){
return BrainSocket::error(array('There was a Laravel App Error!'));
});
由于Laravel 5中没有events.php
,只需弹出app\providers\EventServiceProvider.php
并按如下所示进行修改:
<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use BrainSocket;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\SomeEvent' => [
'App\Listeners\EventListener',
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
$events->listen('generic.event',function($client_data){
return BrainSocket::message('generic.event',array('message'=>'A message from a generic event fired in Laravel!'));
});
$events->listen('app.success',function($client_data){
return BrainSocket::success(array('There was a Laravel App Success Event!'));
});
$events->listen('app.error',function($client_data){
return BrainSocket::error(array('There was a Laravel App Error!'));
});
}
}