I have a Laravel model with a simple function in it. But for some reason I get this error:
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
Here is my Model:
class Dish extends Model
{
public function sum() {
return $this->attributes['begin'] + 10;
}
}
In my controller I do:
$model->sum();
Anyone knows how I can add the function to my model?
Many thanks in advance!
$model = Dish::with('sum')->where('id', 3)->first();or something ?$this->attributes['begin'] + 10, could you just do$this->begin + 10? Not sure why that would be a problem, but it's a hunch. Laravel thinks it's getting an eloquent relationship here, see Simon's comment above.