I'm trying to get sum of columns in relationship model but i get this error
Call to a member function addEagerConstraints() on float
Code
model
public function cableLentgh()
{
return $this->links()->sum('cable_length');
}
Logic
- my model has relationship to
link
model like this
public function links() { return $this->hasManyThrough(Link::class, Segment::class, 'hthree_id', 'segment_id'); }
- in
links
table I have column namedcable_length
where numbers are stored - now I want to have SUM of those numbers.
Any idea?
Update
full error detail
exception: "Error"
file: "C:\laragon\www\web\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php"
line: 578
message: "Call to a member function addEagerConstraints() on float"