SuperTron
SuperTron

Reputation: 4243

Neo4J and Laravel 4 Models

I'm about to start a new web project, and I've decided to use Laravel 4. However, due to the structure of the data I will need to store, I've also decided on Neo4J as the database. Now, I have installed a Laravel package for dealing with Neo4J, which can be found here and I can access the Neo4J database using the usage examples.

However, I'm now at a complete loss as to how to write Eloquent models for this new DB, and how to use the Laravel Auth class with it. I used to use Codeigniter without an ORM, so I understand that model structure, but I have no idea how to use the Eloquent ORM with Neo4J, or how to hack my models and authentication so they don't use the ORM. My guess is that I will likely have to write my own queries and not rely on the Laravel query builder or Eloquent, but I have no idea how to start this process or how to write the models containing these queries.

I have read everything I can find on the Laravel site, but anything to do with authentication and database access assumes a non-graph database. If anyone has any tips on what to read or where to look for more info I'd appreciate it.

Upvotes: 2

Views: 1516

Answers (4)

Mahmoud Zalt
Mahmoud Zalt

Reputation: 31170

Here's a good laravel package for Neo4j: http://github.com/Vinelab/NeoEloquent It almost uses the same functions of Eloquent. And it has a very good documentation.

Upvotes: 0

Sándor Tóth
Sándor Tóth

Reputation: 763

We know the differences between Neo4j and Mysql. But sometimes we need to use similar functionalities what Eloquent gives. So I suggest to follow this project: NeoEloquent

Upvotes: 0

SuperTron
SuperTron

Reputation: 4243

Well, I ended up writing my own neo4j driver for Laravel 4.1. If anyone's interested, you can find it here. As to storing auth data in Neo4J, I wrote my own authentication driver for that. I also ended up creating my own validators to check for database specific things (such as unique).

Upvotes: 5

beech
beech

Reputation: 1064

You won't be able to use Eloquent or Fluent with Neo4j, they just aren't supported. And graph databases are structured very differently so maybe never will be.

Your models shouldn't be worried about how it is stored, that's the job of the repository. And your Neo4J code should live in there. For example, in your repository you may have:

public function find($id)
{
    return Neo4j::getNode($id);
}

Then in your controller you can call:

MyRepository::find(123);

You shouldn't be storing auth details in a graph database, they should still be in MySQL or something similar.

There's some more reading on repositories here http://culttt.com/2013/07/08/creating-flexible-controllers-in-laravel-4-using-repositories/. However I haven't found any Neo4J specific examples.

Hope that helps.

Upvotes: 0

Related Questions