Closed genggui001 closed 3 years ago
Hey @genggui001, you can extend NeoEloquent:
AppServiceProvider.php
<?php
namespace App\Providers;
use App\Grammar;
use Illuminate\Support\ServiceProvider;
use Vinelab\NeoEloquent\Connection;
use Vinelab\NeoEloquent\Schema\Grammars\CypherGrammar;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app['db']->extend('neo4j', function($config)
{
$conn = new Connection($config);
$conn->setQueryGrammar(new Grammar());
$conn->setSchemaGrammar(new CypherGrammar());
return $conn;
});
}
}
Grammar.php
<?php
namespace App\Database;
use Vinelab\NeoEloquent\Query\Grammars\CypherGrammar;
class Grammar extends CypherGrammar
{
public function modelAsNode($labels = null, $relation = null)
{
if ($labels === null) {
return 'n';
}
if ($relation !== null) {
$labels = 'with_' . $relation . '_' . $labels;
}
if (is_array($labels)) {
return mb_strtolower(array_last($labels));
}
return mb_strtolower($labels);
}
}
You can modify modelAsNode
so it fits your needs.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Cutting the Chinese string with the substr() and stitching it back will cause garbled characters. Use lcfirst() to solve the problem
$labels = lcfirst($labels);