Vinelab / NeoEloquent

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

Getting error when I'm working with Edges #266

Closed ander-oliveira closed 4 years ago

ander-oliveira commented 6 years ago

Hi =) I'm using Laravel 5.5 and I'm trying to get information like labels from an edge between nodes (Curso and Institute) in a relationship but I'm having the following error:

"No node id specified"

My Models are:

Instituto.php

namespace App;

use App\Curso as Curso;

use Vinelab\NeoEloquent\Eloquent\Model as NeoEloquent;
use Vinelab\NeoEloquent\Eloquent\Edges\Relation;
use Vinelab\NeoEloquent\Eloquent\Edges\EdgeIn;
use Vinelab\NeoEloquent\Eloquent\Edges\EdgeOut;
use Vinelab\NeoEloquent\Eloquent\Relations\HasMany;

class Instituto extends NeoEloquent {

    protected $label = 'INSTITUTO';
    protected $primaryKey = 'sigla';
    protected $fillabe = [
        'sigla', 
        'nome', 
        'id'
    ];

    public $incrementing = false;

    public function instituto(){
        return $this->hasMany('App\Curso', 'MANTEM');
    }
}

Curso.php

namespace App;

use Vinelab\NeoEloquent\Eloquent\Model as NeoEloquent;
use Vinelab\NeoEloquent\Eloquent\Edges\Relation;
use Vinelab\NeoEloquent\Eloquent\Edges\EdgeIn;
use Vinelab\NeoEloquent\Eloquent\Edges\EdgeOut;

class Curso extends NeoEloquent {

    protected $label = 'CURSO';
    protected $primaryKey = 'sigla';
    protected $fillabe = [
        'sigla', 
        'nome_curso'
    ];

    public $incrementing = false;

    public function curso(){
        return $this->belongsToMany('App\Instituto', 'MANTEM');
    }

}

And my Controller is:

CursoController.php

namespace App\Http\Controllers;

use App\Curso as Curso;
use App\Instituto as Instituto;
use Illuminate\Http\Request;
use Vinelab\NeoEloquent\Eloquent\Edges\Finder;
use Vinelab\NeoEloquent\Eloquent\Edges\EdgeIn;
use Vinelab\NeoEloquent\Eloquent\Edges\EdgeOut;
use Vinelab\NeoEloquent\Eloquent\Edges\Relation;

class CursoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index() {

        $instituto = Instituto::find('IMC');
        $curso = Curso::all();

        $teste = $instituto->instituto()->edges($curso);

        return view('test', compact(['teste']));

    }

Someone can help me to solve this error?

Mulkave commented 6 years ago

Can you please provide the code where you get the Edge and what you do with it? It seems that you have not run a query before trying to access the Edge.

ander-oliveira commented 6 years ago

The code is in CursoController.php, on index()

I'm searching the Instituto that has 'IMC' property, searching all courses, and after searching $curso that has this relation with 'IMC'.

mrbardia72 commented 6 years ago

I tested the code above, but I went through the error

Unable to retrieve server info [401]: Headers: Array ( [Date] => Tue, 07 Aug 2018 08:25:54 GMT [Content-Type] => application/json; charset=UTF-8 [WWW-Authenticate] => None [Content-Length] => 144 [Server] => Jetty(9.2.z-SNAPSHOT) ) Body: Array ( [errors] => Array ( [0] => Array ( [message] => No authorization header supplied. [code] => Neo.ClientError.Security.AuthorizationFailed ) ) )

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.