*/ class Job extends Model { use PresentableTrait; protected $presenter = JobPresenter::class; protected $guarded = ['id', 'created_at', 'updated_at']; public function project() { return $this->belongsTo(Project::class, 'project_id'); } public function worker() { return $this->belongsTo(User::class, 'worker_id'); } public function tasks() { return $this->hasMany(Task::class)->orderBy('progress')->orderBy('position'); } public function type() { return $this->type_id == 1 ? 'Project' : 'Additional'; } public function getProgressAttribute() { return $this->tasks->isEmpty() ? 0 : $this->tasks->avg('progress'); } public function getReceiveableEarningAttribute() { return $this->price * ($this->progress / 100); } }