app/DataTables/TeachersScheduleDataTable.php
/**
     * Get query source of dataTable.
     *
     * @param \App\Models\TeachersSchedule $model
     * @return \Illuminate\Database\Eloquent\Builder
     */
Get query source of dataTable.
Get query source of dataTable .
public function query(Teachers $model)
    {
        if ($this->type === "teachers") {
            return $model
                ->query()
                ->join('subjects', 'subjects.teacher_id', '=', 'teachers.id')
                ->join('classrooms', 'subjects.classroom_id', '=', 'classrooms.id')
                ->where('teachers.user_id', auth()->user()->id)
                ->select(
                    'teachers.firstname',
                    'teachers.lastname',
                    'teachers.phone',
                    'subjects.name AS subject_name',
                    'subjects.days',
                    'subjects.start_at',
                    'subjects.end_at',
                    'classrooms.name AS class_name',
                    'classrooms.token AS token_class'
                );
        }
        return $model
            ->query()
            ->join('subjects', 'subjects.teacher_id', '=', 'teachers.id')
            ->join('classrooms', 'subjects.classroom_id', '=', 'classrooms.id')
            ->select(
                'teachers.firstname',
                'teachers.lastname',
                'teachers.phone',
                'subjects.name AS subject_name',
                'subjects.days',
                'subjects.start_at',
                'subjects.end_at',
                'classrooms.name AS class_name',
                'classrooms.token AS token_class'
            );
    }
public function query ( Teachers $ model ) { if ( $ this -> type === " teachers " ) { return $ model -> query ( ) -> join ( 'subjects' , 'subjects.teacher_id' , '=' , 'teachers.id' ) -> join ( 'classrooms' , 'subjects.classroom_id' , '=' , 'classrooms.id' ) -> where ( 'teachers.user_id' , auth ( ) -> user ( ) -> id ) -> select ( 'teachers.firstname' , 'teachers.lastname' , 'teachers.phone' , 'subjects.name AS subject_name' , 'subjects.days' , 'subjects.start_at' , 'subjects.end_at' , 'classrooms.name AS class_name' , 'classrooms.token AS token_class' ) ; } return $ model -> query ( ) -> join ( 'subjects' , 'subjects.teacher_id' , '=' , 'teachers.id' ) -> join ( 'classrooms' , 'subjects.classroom_id' , '=' , 'classrooms.id' ) -> select ( 'teachers.firstname' , 'teachers.lastname' , 'teachers.phone' , 'subjects.name AS subject_name' , 'subjects.days' , 'subjects.start_at' , 'subjects.end_at' , 'classrooms.name AS class_name' , 'classrooms.token AS token_class' ) ; }
Get query source of dataTable.
Get query source of dataTable .