Did you add relationship grade method in your Student model?
Jan 2, 2017
8
Level 2
Can't query pivot table
so i have a pivot table that handles both students and grades i have a Grade model and a student model . so a student hasOne Grade and a Grade hasManny Students. i can query like from grade and get all student like $grade->$students and it gets all students but i can't get get the student's grade in the student profile like $student->grade->grade_name kind of thing does work out don't know why .
public function show($id)
{
$student=Student::withTrashed()->where('id',$id)->first();
return view('students.show',compact('student'));
//hear i would like to be able to query and display the students grade }
@foreach($grades->students as $students)
<td>
{{$students->name}}
</td>
<td>
{{$students->created_at->format('d-m-Y')}}
</td>
<td>
{{$students->age}}
</td>
<td>
{{--<a href="#" class="table-action-btn h3"><i class="mdi mdi-pencil-box-outline text-success"></i></a>--}}
<a href="{{url('class/remove-student/' . $grades->id . '/' . $students->id)}}" class="table-action-btn h3"><i class="mdi mdi-close-box-outline text-danger"></i></a>
</td>
</tr>
@endforeach
thats my view for all students in a particular grade that works fine .
Please or to participate in this conversation.