Skip model accessor

后端 未结 4 846
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 13:56

I got a model called Run which contains this method:

public function getNameAttribute($name){
    if($name == \'Eendaags\')
        return $this->race_edition         


        
4条回答
  •  孤独总比滥情好
    2021-01-31 14:29

    I was running into an issue with Eloquent accessors and form model binding - by formatting an integer with money_format, the value was no longer being loaded into the form number input field.

    The workaround I am using is to create an accessor with a different name:

    public function getRevenueDollarsAttribute($value)
    {
        return money_format('$%i', $this->revenue);
    }
    

    This provides me with an accessor without affecting the form model binding.

提交回复
热议问题