Skip to content

Getting exception Call to undefined method, when trying to append accessor with new syntax #40556

@itxshakil

Description

@itxshakil
  • Laravel Version: 8.77.1
  • PHP Version: 8.0
  • Database Driver & Version: mysql

Description:

I am getting issue
Call to undefined method App\Models\Product::getLowestPriceAttribute()
Even though I have defined lowestPrice function that returns CastsAttribute.

public function lowestPrice()
{
return \Illuminate\Database\Eloquent\Casts\Attribute::get(function(){
return 0; #some calculation
});
}

Working:
$product->lowestPrice

Not Working:
$product->append('lowestPrice');

Throws
Call to undefined method App\Models\Product::getLowestPriceAttribute()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions