1
0
mirror of https://github.com/robonen/education-project.git synced 2026-03-20 02:44:31 +00:00

index метод

This commit is contained in:
nikden13
2020-12-09 13:42:28 +07:00
parent 3c93886fef
commit 1765cf44d0
3 changed files with 29 additions and 3 deletions

View File

@@ -21,14 +21,30 @@ class TimetableController extends Controller
]);
$builder = Timetable::all()->sortBy('timeStart');
$timetables = (new TimetableFilter($builder, $request))->apply()->values();
$arrayTimetables = [];
$filterTimetables = collect([]);
foreach ($timetables as $timetable) {
$subject = $timetable->subject->name;
$teacher = $timetable->teacher->only('name', 'surname', 'patronymic');
$class = $timetable->schoolClass->only('number', 'letter');
$filterTimetables->push([
'id' => $timetable['id'],
'date' => $timetable['date'],
'time_start' => $timetable['time_start'],
'time_end' => $timetable['time_end'],
'classroom' => $timetable['classroom'],
'subject' => $subject,
'teacher' => $teacher,
'class' => $class,
]);
}
$dateTimetables = [];
for ($i = 0; $i < 6; $i++) {
$date = Carbon::parse($request->input('date'))
->addDays($i)
->format('Y-m-d');
array_push($arrayTimetables, [$date => $timetables->where('date', $date)->values()]);
array_push($dateTimetables, [$date => $filterTimetables->where('date', $date)->values()]);
}
return response()->json($arrayTimetables, 200);
return response()->json($dateTimetables, 200);
}
//Получение урока

View File

@@ -13,6 +13,11 @@ class Subject extends Model
'name',
];
protected $hidden = [
'created_at',
'updated_at',
];
public function banktasks()
{
return $this->hasMany(BankTask::class);

View File

@@ -13,6 +13,11 @@ class Timetable extends Model
'updated_at',
];
protected $hidden = [
'created_at',
'updated_at',
];
public function teacher()
{
return $this->belongsTo(Teacher::class);