- Laravel Version: 5.5.35
- PHP Version: 7.0.10
- Database Driver & Version: MySQL 5.7.14
Description:
I have a pivot model called UserTask in which I have an accessor function:
class UserTask extends Pivot implements HasMedia
{
use HasMediaTrait;
public function getCompletedAttribute()
{
return $this->getMedia()->isEmpty() && $this->completed;
}
public function task()
{
return $this->belongsTo(Task::class);
}
}
I specify the relation in my Task model like this:
class Task extends Model
{
public function users()
{
return $this->belongsToMany(User::class, 'user_task')->using('App\Models\UserTask')->withPivot('completed');
}
}
I get the following error:
"message": "Undefined property: App\Models\UserTask::$completed",
Anyone know why this is happening?