编辑:好的,我在测试期间更新了这篇文章几次,现在它可以工作了……我让下面的正确代码..。/EDIT
从今天早上开始,我尝试使用“新氧/新客户端”作为一个ServiceProvider和一个门面来安装新的Laravel5.1
为此,我需要在我的composer.json中使用"neoxygen/neoclient":“^3.0
然后,我在“应用程序/提供者”中创建了一个名为"NeoClientServiceProvider“的新ServiceProvider。
在其register方法中;我已经实例化了连接:
public function register()
{
$this->app->singleton('neoclient', function ($app) {
return ClientBuilder::create()
->addConnection('default', 'http', env('NEO4J_HOST'), intval(env('NEO4J_PORT')), true, env('NEO4J_USER'), env('NEO4J_PASSWORD'))
->setDefaultTimeout( intval(env('NEO4J_TIMEOUT')) )
->setAutoFormatResponse(true)
->build();
});
}接下来,我在“ServiceProvider /app.php”中注册了配置,方法是在提供程序中包含完整的类,并设置别名:
'providers' => [
...
App\Providers\NeoClientServiceProvider::class
...
],
'aliases' => [
...
'NeoClient' => App\NeoClient::class
...
]我还创建了一个扩展Facade的NeoClient类,如下所示:
<?php namespace App;
use \Illuminate\Support\Facades\Facade;
class NeoClient extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'neoclient'; }
}最后,我有一个这样的控制器:
<?php namespace App\Http\Controllers;
use NeoClient;
class GenreController extends Controller
{
public function __construct()
{
// needed authentication
//$this->middleware('oauth');
}
public function create()
{
$data = NeoClient::sendCypherQuery("MATCH (g:Genre) RETURN COUNT(g) AS total")->getRows();
return response()->json($data);
}
}附言:我知道"NeoEloquent“的存在,但我不想用这个…
++
弗雷德。
发布于 2015-10-03 17:38:46
https://stackoverflow.com/questions/31452932
复制相似问题