belongsTo('App\Models\Student'); } public function getStudentName() { return empty($this['student']) ? '' : $this['student']->name; } public function getCourseName() { return empty($this['course']) ? '' : $this['course']->name; } public function studentCourse() { return $this->belongsTo('App\Models\StudentCourse'); } public function course() { return $this->belongsTo('App\Models\Course'); } public function getDuration() { $res = ''; if(!empty($this['begin_date_time']) && !empty($this['end_date_time'])) { $begin_time = strtotime($this['begin_date_time']); $end_time = strtotime($this['end_date_time']); if($end_time > $begin_time) { $diff_time = $end_time - $begin_time; $tmp = floor($diff_time / 3600); $diff_time = $diff_time % 3600; if(!empty($tmp)) { $res .= $tmp . '小时'; } $tmp = floor($diff_time / 60); $diff_time = $diff_time % 60; if(!empty($tmp)) { $res .= $tmp . '分钟'; } if(!empty($diff_time)) { $res .= $diff_time . '秒'; } return $res; } } return $res; } }