product->priceList()->count() > 0) { $priceBook = $priceList->product->priceList()->first(); $priceList->product->price = $priceBook->price; $priceList->product->save(); } }); } /** * Validation rules * * @var array */ public static $rules = [ ]; protected static $logAttributes = [ 'name', 'price', 'product.name', 'ownedBy.name', ]; public $table = 'price_list'; public $fillable = [ 'name', 'price', 'product_id', 'company_id' ]; protected $mustBeApproved = false; protected $dates = ['deleted_at', 'created_at', 'updated_at']; protected $appends = array('nameProduct'); public function getNameProductAttribute(){ return $this->product->name.' - '.$this->name; } /** * @param Model $model * @param string $attribute * @return array */ protected static function getRelatedModelAttributeValue(Model $model, string $attribute): array { return ActivityLogHelper::getRelatedModelAttributeValue($model, $attribute); } public function product() { return $this->belongsTo(Product::class); } public function currency() { return $this->belongsTo(Currency::class); } public function company() { return $this->belongsTo(Company::class); } }