I am building a school management system I want once a teacher gets to the time table section they will be able to see the subjects they are teaching that day and they should also see the room and time but I am receiving this error ‘Attempt to read property “week_id” on null’
the following are the codes
static public function getMyTimeTable($class_id, $subject_id)
{
// return self::where('class_id', '=', $class_id)->delete();
$getWeek = week1model::getWeekUsingName(date('1'));
return ClassSubjectTimetable::getRecordClassSubject($class_id, $subject_id, $getWeek->week_id);
}
this line of code is the one supposed to access the week id but its returning null
$getWeek = week1model::getWeekUsingName(date('1'));
the following models are working together with the above model
week1 model->this model is supposed to fetch the name from the week table by comparing the name received from the model above
static public function getWeekUsingName($weekName)
{
return week1model::where('name', '=', $weekName)->first();
}
classsubjecttimetable model
static public function getRecordClassSubject($class_id, $subject_id, $week_id)
{
return self::where('class_id', '=', $class_id)->where('subject_id', '=', $subject_id)->where('week_id', '=', $week_id)->first();
}//
the blade file
@foreach ($getRecord as $value)
<tr>
<td> {{$value->id}}</td>
<td> {{$value->class_name}}</td>
<td> {{$value->subject_name}}</td>
<td> {{$value->subject_type}}</td>
<td>
@php
$ClassSubject = $value->getMyTimetable($value->class_id, $value->subject_id);
@endphp
@if(!empty($ClassSubject))
{{date('h:i A', strtotime($ClassSubject->start_time))}}
to {{date('h:i A', strtotime($ClassSubject->end_time))}}
<br>
Room number::{{$ClassSubject->room_number}}
@endif
</td>
<td> {{date('d-m-Y H:i A', strtotime($value->created_at))}}</td>
<td>
<a href="{{url('/teacher/my_class_subject/timetable/' . $value->class_id . '/' . $value->subject_id)}}"
class="btn btn-primary">My
TimeTable</a>
</td>
</tr>
@endforeach
I am trying to display the current day subjects to be taught the time and roon number
12