php - laravel accessors in controller? -


i've add accessors , mutators in laravel model.

public function getamountattribute($amount) {     return ($amount) / 100; } public function setamountattribute($amount) {     $this->attributes['amount'] = $amount * 100; } 

these working fine me. @ 1 place facing issue : issue want apply aggregate function in controller amount field. accessors not working.

model::with(['xxx'])->where('parent_id', $id)->sum('amount') 

value of $id fine checked. it's giving me sum of amount field parent_id equals $id. should give results after diving 100.

thanks in advance.

accessors , mutators allow format eloquent attributes when retrieving them model or setting value.

... not while querying table.

model::with(['xxx'])     ->addselect(db::raw('sum(`table`.amount/100) sum_of_amounts'))     ->where('parent_id', $id)     ->get(); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -