NeoEloquent. Include the package to your composer.json and run composer improvement

NeoEloquent. Include the package to your composer.json and run composer improvement

An Eloquent Neo4j Graph Driver

Installation

Include the ongoing company in app/config/app.php :

The company shall register all the necessary classes with this package and also will alias the Model course to NeoEloquent in order to just expand NeoEloquent in your models.

Setup

in app/config/database.php or perhaps in situation of an configuration that is environment-based.php make neo4j your default connection:

Add the text defaults:

Documentation

Models

As easy as it’s, NeoEloquent will create the standard node label through the course title, in this instance it’s going to be :User . Learn about node labels right here

Namespaced Models

By using namespaces along with your models the label will look at the namespace that is full.

The generated label from that relationship will likely be VinelabCmsAdmin , this really is essential to make sure labels usually do not clash in instances where we introduce another Admin example like Vinelab\Blog\Admin then points gets messy with :Admin into the database.

Custom Node Labels

You might specify the label(s) you want to be utilized rather than the default created, also, they are instance sensitive and painful so they really will undoubtedly be kept as put right here.

NeoEloquent has a fallback help when it comes to $table adjustable BirminghamAL escort which is used if discovered and there clearly was no $label defined from the model.

Usually do not concern yourself with the labels formatting, You may specify them as array(‘Label1’, ‘Label2’) or split them by a line : and prepending all of them with a : is optional.

Smooth Deleting

Make it possible for soft deleting you’ll need certainly to utilize Vinelab\NeoEloquent\Eloquent\SoftDeletingTrait in place of Illuminate\Database\Eloquent\SoftDeletingTrait and simply like Eloquent you may need the $times in your models the following:

Relationships

Let us proceed through a few examples of relationships between Nodes.

One-To-One

This represents an OUTGOING relationship way from the :User node to a :Phone .

Saving

The Cypher done by this declaration shall be the following:

Defining The Inverse Of The Connection

This represents AN INCOMING relationship way from the :User node for this :Phone node.

Associating Models

Simply because it is much more than just setting the foreign key attribute on the parent model that we do not deal with foreign keys, in our case. In Neo4j (and Graph as a whole) a relationship is an entity itself that will likewise have characteristics of its very own, ergo the introduction of sides

Note: Associated models will not continue relations automatically when calling associate() .

The Cypher done by this declaration will be the following:

The Cypher performed by this declaration shall be the following:

One-To-Many

This represents an OUTGOING relationship way from the :User node to your :Post node.

Just like One-To-One relationships the returned value from a save() declaration is an Edge[In|Out]

The Cypher done by this declaration shall be the following:

Determining The Inverse With This Connection

This represents AN INBOUND relationship direction from the :User node to the :Post node.

Many-To-Many

This represents an OUTGOING relationship between a :User node and another :User .

Or utilizing the attach() technique:

The Cypher done by this declaration will be the following:

$mc follows $jd back:

The Cypher done by this declaration will be the following:

obtain the followers of $jd

The Cypher done by this statement shall be the following:

Dynamic Properties

Polymorphic

The idea behind Polymocrphic relations is solely relational to your bone however when it comes down to graph our company is representing it as a HyperEdge.

Hyper edges involves three models, the moms and dad model, hyper model and related model represented in the following figure:

Likewise in rule this is represented by three models consumer Comment and Post where a person with id 1 articles a Post and a person with id 6 COMMENTED a touch upon that Post the following:

So that things easy but nonetheless concerning the three models we are going to need to pass the $morph which can be any model that is commentable within our instance it really is either a video clip or a Post model.

Note: Make certain to contain it defaulting to null to ensure we could Dynamicly or Eager load with $user->comments down the road.

Producing a Comment aided by the create() technique.

As always we shall have came back an advantage, but this right time it is not directed it is an example of HyperEdge , read more about HyperEdges right here.

Or perhaps you may save yourself a Comment example:

Also most of the functionalities present in a BelongsToMany relationship are supported like attaching models by Ids:

Or models that are detaching

Retrieving Polymorphic Relations