1. Go to this page and download the library: Download digitalcloud/neo-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/ */
class Phone extends NeoEloquent {
public function user()
{
return $this->belongsTo('User');
}
}
$account = Account::find(1986);
// $relation will be Vinelab\NeoEloquent\Eloquent\Edges\EdgeIn
$relation = $user->account()->associate($account);
// Save the relation
$relation->save();
class User extends NeoEloquent {
public function posts()
{
return $this->hasMany('Post', 'POSTED');
}
}
$user = User::find(1);
$post = new Post(['title' => 'The Title', 'body' => 'Hot Body']);
$user->posts()->save($post);
class Post extends NeoEloquent {
public function author()
{
return $this->belongsTo('User', 'POSTED');
}
}
class User extends NeoEloquent {
public function followers()
{
return $this->belongsToMany('User', 'FOLLOWS');
}
}
$jd = User::find(1012);
$mc = User::find(1013);
$jd->followers()->save($mc);
$jd->followers()->attach($mc);
// Or..
$jd->followers()->attach(1013); // 1013 being the id of $mc ($mc->getKey())
$mc->followers()->save($jd);
$followers = $jd->followers;
class Phone extends NeoEloquent {
public function user()
{
return $this->belongsTo('User');
}
}
$phone = Phone::find(1006);
$user = $phone->user;
// or getting an attribute out of the related model
$name = $phone->user->name;
class User extends NeoEloquent {
public function comments($morph = null)
{
return $this->hyperMorph($morph, 'Comment', 'COMMENTED', 'ON');
}
}
$video = Video::with('comments')->find(3);
foreach ($video->comments as $comment)
{
//
}
class Comment extends NeoEloquent {
public function commentable()
{
return $this->morphTo();
}
}
$postComment = Comment::find(7);
$post = $comment->commentable;
$videoComment = Comment::find(5);
$video = $comment->commentable;
// You can also eager load them
Comment::with('commentable')->get();
class Comment extends NeoEloquent {
public function post()
{
return $this->morphTo('Post', 'ON');
}
public function video()
{
return $this->morphTo('Video', 'ON');
}
}
class User extends NeoEloquent {
public function comments($morph = null)
{
return $this->hyperMorph($morph, 'Comment', 'COMMENTED', 'ON');
}
}
class Post extends NeoEloquent { // Video is the same as this one
public function comments()
{
return $this->morphMany('Comment', 'ON');
}
}
class Comment extends NeoEloquent {
public function commentable()
{
return $this->morphTo();
}
}
class Book extends NeoEloquent {
public function author()
{
return $this->belongsTo('Author');
}
}
foreach (Book::with('author')->get() as $book)
{
echo $book->author->name;
}
class Location extends NeoEloquent {
public function user()
{
return $this->belongsTo('User', 'LOCATED_AT');
}
}
$edge = $user->comments($post)->attach($comment);
// Access the left and right edges
$left = $edge->left();
$user = $left->parent();
$comment = $left->related();
$right = $edge->right();
$comment = $right->parent();
$post = $right->related();
// Create a new relationship
$relation = $location->associate($user); // Vinelab\NeoEloquent\Eloquent\Edges\EdgeIn
// Save the relationship to the database
$relation->save(); // true
class Post extends NeoEloquent {
public function photos()
{
return $this->hasMany('Photo', 'PHOTO');
}
public function videos()
{
return $this->hasMany('Video', 'VIDEO');
}
}
MATCH (account:`Account`), (user:`User`)
WHERE id(account) = 1986 AND id(user) = 9862
MERGE (account)<-[rel_user_account:ACCOUNT]-(user)
RETURN rel_user_account;
MATCH (user:`User`)
WHERE id(user) = 1
CREATE (user)-[rel_user_post:POSTED]->(post:`Post` {title: 'The Title', body: 'Hot Body', created_at: '15-05-2014', updated_at: '15-05-2014'})
RETURN rel_user_post;
MATCH (user:`User`), (followers:`User`)
WHERE id(user) = 1013 AND id(followers) = 1012
CREATE (user)-[rel_user_followers:FOLLOWS]->(followers)
RETURN rel_follows;
MATCH (user:`User`), (followers:`User`), (user)-[rel_user_followers:FOLLOWS]-(followers)
WHERE id(user) = 1012
RETURN rel_follows;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.