[EDIT] : OK, I updated this post several times during my tests and now it's working... I left the correct code here below... [/EDIT]
Since this morning, I've been trying to use "Neoxygen/Neoclient" as a ServiceProvider and a Facade for a new fresh installation of Laravel 5.1
For this, I've required "neoxygen/neoclient": "^3.0" in my composer.json
Then I've created a new ServiceProvider into "app/Providers" called "NeoClientServiceProvider".
In its register method; I've instantiated the connection :
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();
});
}
Next, I've registered the ServiceProvider in "config/app.php" by including the Full Class in my providers and by setting an alias :
'providers' => [
...
App\Providers\NeoClientServiceProvider::class
...
],
'aliases' => [
...
'NeoClient' => App\NeoClient::class
...
]
I also created a NeoClient Class that extends Facade like this :
<?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'; }
}
Finally, I have a Controller like this :
<?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);
}
}
PS: I know "NeoEloquent" exists but I don't want to use this one...
++
Fred.
Off course You can ! Here's the link of the client :
https://github.com/graphaware/neo4j-php-client
++