jeudi 6 décembre 2018

Is any way to get relations for all order if is polymorphic?

I have an Order model, Product and SerialsNo. You can have order ID and list of products and one to many serialNo.

Order

public function products() {
    return $this->hasMany('App\Product', 'order_id', 'id');
}

Product

public function serialNumbers() {
    return $this->morphMany('App\SerialNumber', 'serial_numberable');
}

SerialNumber

public function serial_numberable() {
    return $this->morphTo();
}

if i would like get serial numbers for products

$sn = Product::find(1); 
dd($sn->serialNumbers);

Seems to be fine but i would like get order id and serial numbers like this way:

dd($order->products()->serialNumbers);

but i have info

"Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$serialNumbers"

Is any way to do ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire