mercredi 29 juin 2016

Relationships returning wrong/null data (Laravel 5.2)

Got a domain table which has a One To Many relationship with domain_hosts_table, server_hosts_table and systems_table. So far so good.

Calling the table data:

$domains = Domain::with('domain_host', 'server_host', 'system')->get();

Domain model :

public function domain_host()
{
    return $this->hasOne('App\DomainHost', 'id');
}

public function server_host()
{
    return $this->hasOne('App\ServerHost', 'id');
}

public function system()
{
    return $this->hasOne('App\System', 'id');
}

DomainHost, ServerHost, System model :

public function domains()
{
    return $this->hasMany('App\Domain');
}

Domains table :

enter image description here

So far so good.

Let's take a look at what this particular table returns while being foreached.

enter image description here

The first 2 rows should be the same (basing on their IDs), and all rows after the first 2 are just empty.

(dd of the fetched data, notice the relations being empty at 4th object, 1st object actually has data).

enter image description here



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2997ayj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire