1. Go to this page and download the library: Download dwoodard/neo4j-eloquent library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dwoodard / neo4j-eloquent example snippets
namespace App\Models\Neo4j;
use Neo4jEloquent\Model;
class User extends Model
{
protected array $labels = ['User'];
protected array $fillable = [
'name',
'email',
'age',
'city',
];
protected array $casts = [
'age' => 'integer',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}
// Create a user
$user = User::create([
'name' => 'John Doe',
'email' => '[email protected]',
'age' => 30,
'city' => 'San Francisco'
]);
// Find all users
$users = User::all();
// Find a specific user
$user = User::find($userId);
// Query with conditions
$adults = User::label('User')
->where('age', '>', 18)
->orderBy('name')
->get();
$users = User::all();
// This will return properly formatted JSON with all node data
return response()->json($users);
// Or convert to array manually
$usersArray = $users->map(fn($user) => $user->toArray());
use Neo4jEloquent\Neo4jService;
$neo4j = app(Neo4jService::class);
$result = $neo4j->runRaw('
MATCH (p:Person)-[:FRIENDS_WITH]->(f:Person)
WHERE p.city = $city
RETURN p.name, count(f) as friend_count
', ['city' => 'San Francisco']);
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Neo4jEloquent\Node;
class TestNeo4j extends Command
{
protected $signature = 'neo4j:test';
protected $description = 'Test Neo4j connection';
public function handle()
{
try {
$testNode = Node::label('TestNode')->create([
'name' => 'Test',
'created_at' => now()
]);
$this->info('✅ Neo4j connection successful!');
// Clean up
$testNode->delete();
} catch (\Exception $e) {
$this->error('❌ Neo4j connection failed: ' . $e->getMessage());
}
}
}