Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
634 stars 200 forks source link

I can not create relationships #172

Closed gburu98-zz closed 8 years ago

gburu98-zz commented 8 years ago

When trying to save a relationship he answers: Call to a member function phone() on null, which it is the failure? person route error

Mulkave commented 8 years ago

What version of Laravel are you using?

gburu98-zz commented 8 years ago

Using Laravel 5.2.31

Mulkave commented 8 years ago

Can you please try use NeoEloquent instead of use Vinelab\NeoEloquent\EloquentModel as NeoEloquent in your model class.

Also make sure you have the NeoEloquentServiceProvider in your providers array in config/app.php

gburu98-zz commented 8 years ago

I did what you told me, but still the same error "Call to a member function save() on null "... now is save() and no phone error () provider

Mulkave commented 8 years ago

Oh just noticed that your relationship method has 'Phone' while it should be the actual class name with the full namespace. (i.e. App\Phone) or with a use App\Phone at the top you may use Phone::class. Can you please confirm?

gburu98-zz commented 8 years ago

I leave my routes.php images and test.php (Model) route model

Mulkave commented 8 years ago

It is not required that you create the phone prior to calling $user->phone()->save($phone1);. You may try one of the following:

$prueba = Prueba::createWith(['name' => 'A'], [
  'phone' => [
    'number' => '123123',
  ]
]);

// get the phone
$phone = $prueba->phone;

Or if you wish to keep them separated you can use attach instead of save

$prueba = Prueba::create(['name' => 'A']);

$phone = Phone::create(['number' => '987654321']);

$prueba->phone()->attach($phone);
gburu98-zz commented 8 years ago

It worked perfectly, thank you very much to solve my problem!!!

As I locate the relationship via Neo4j browser, but I found the node "0 relationships"... node

Mulkave commented 8 years ago

@gburu98 glad it worked 😄

That's probably the Neo4j browser saying that it is not Displaying any relationships, can you please try double-clicking that node?

gburu98-zz commented 8 years ago

Thanks again!!! I'm new to Neo4j, sorry for my rookie mistakes. They did an excellent job in NeoEloquent I congratulate you! rel