-
-
Notifications
You must be signed in to change notification settings - Fork 855
Closed
Labels
Description
How do i filter datatable queries from my controller, and how do i return a collection or array to my view from datatable controller
I have 2 issues.
No 1: I am trying to filter my datatable queries
eg.
When a class group is selected only record to that class show be displayed, if no class group is selected, all the class list should be displayed.
No 2: I want to show all teachers in the database to the view in yajra table.
Here is my sample code
public function getSubject(SubjectDataTable $dataTable){
$allTeachers = (new TeacherService())->getSubjectTeacher();
$classID = 10;
return $dataTable->render('staffAuth.classes.subjects', compact(['allTeachers','classID']));
} public function dataTable(QueryBuilder $query): EloquentDataTable
{
return (new EloquentDataTable($query))
->addColumn('class', 'components.subject-class')
->addColumn('subject_teacher', 'components.subject-teachers') i want to be able to access $allTeachers here in the view
->addColumn('action', 'components.subject-edit')
->escapeColumns([])
->setRowId('id');
}
public function query(Subject $model): QueryBuilder
{
if(!empty($this->classID)){
return $model->newQuery()->where('status', 'active')->where('class_id', $this->classID);
}
return $model->newQuery()->where('status', 'active');
}

