4
votes

[EDIT] : OK, i updated this post several times during my tests and now it's working... I let the correct code here below... [/EDIT]

Since this morning, i'm trying to use "Neoxygen/Neoclient" as a ServiceProvider and a Facade into 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 who 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'; }
}

And 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.

1
OK, I found the solution... And I've updated my topic...frednotet
hey can we use neoclient without any framework ......... because we are not using laravel or symphony even we are using nothing like framework.........................simply my question is that if we are not using any framework for core purposes then why should we use them to just use dbmsRavinder Payal

1 Answers

0
votes

Off course You can ! Here's the link of the client :

https://github.com/graphaware/neo4j-php-client

++