mercredi 12 décembre 2018

Use hasMany Relation with Model Attribute

I have the following model:

class User extends Model {

    public function addresses() {
        return $this->hasMany('Addresses');
    }

    public function billAddress() {
        return $this->addresses()->where('id','=', $this->idBill);
    }
}

The following query will result in an empty collection.

\App\User::whereHas('billAddress')->get();

However, any instance of a user has a billAddress.

Is it simply not possible to use $this->attribute in a hasMany relation? Or is there some other way how to achieve this.



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

Aucun commentaire:

Enregistrer un commentaire