lundi 28 mai 2018

Failure to extract data from a relationship with laravel

I am trying to make a one-to-many relationship, but I get the following error

Undefined property: stdClass::$client (View: C:\wamp\www\intranet\resources\views\users\list.blade.php)

The problem is that I am working with an existing database that in the tables does not have id fields, and the foreign keys would also be the typical ones like client_id

My model Client.php

class Client extends Model
{
    protected $connection = 'dpnmwin';

    protected $table = 'nmundfunc';

    public function employee(){

        return $this->hasMany('App\Employee');

    }

}

My model Employee.php

class Employee extends Model
{
    protected $connection = 'dpnmwin';

    protected $table = 'nmtrabajador';

    public function client(){

        return $this->belongsTo('App\Client', 'COD_UND');

    }
}

In nmtrabajador COD_UND field would be the foreign key that relates to nmundfunc.

And I try to get the data out like this: .

but it does not throw me the error, how can I solve it?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2skxcqe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire