Using "Neoxygen / Neoclient" as a ServiceProvider + Facade in Laravel 5.1

[EDIT]: OK, I updated this post several times during my tests, and now it works ... I gave the correct code below ... [/ EDIT]

Starting this morning, I’m trying to use Neoxygen / Neoclient as a ServiceProvider and Facade in the new new Laravel 5.1 installation

To do this, I need a "neo-oxygen / neo-client": "^ 3.0" in my composer.json

Then I created a new ServiceProvider in "app / Providers" called "NeoClientServiceProvider".

In your registration method; I made a 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();
    });
}

Then I registered the ServiceProvider in "config / app.php", including the full class in my providers and setting an alias:

'providers' => [ 
...
App\Providers\NeoClientServiceProvider::class
...
],
'aliases' => [
...
'NeoClient' => App\NeoClient::class
...
]

NeoClient, Facade :

<?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);
}

}

PS: , "NeoEloquent" , ...

++

.

+4

Source: https://habr.com/ru/post/1598206/


All Articles