What i want?
I want to get all products from orders and sum price of products (it depend ot sms price so i use sms_id in product, i call it like this $product->sms->price)
How this will be done?
Here is my models:
class Product extends Model
{
protected $fillable = [];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function orders(){
return $this->hasMany(Order::class);
}
public function sms() {
return $this->hasOne(Sms::class,'id','sms_id');
}
}
class Orders extends Model
{
public function product() {
return $this->belongsTo(Product::class);
}
}
class Sms extends Model
{
public function product() {
return $this->belongsTo(Product::class);
}
}