Hello folks, Thanks for any help. I am still learning Laravel. I am passing data to blade and in a table format where I have actions of edit and delete buttons in the table. So far so good. There is another button on the blade file to print pdf . Everything works fine with the exception of the last data in the table row. When I try to click on the button in the last row eloquent throws an exception
null // app\Http\Controllers\StudentExamsControlle The rest of the data in the above row works or responds perfectly. Any help? I used (using dd) for foe test
public function singleStudent ($student_id){ $singleStudent = StudentExams::find($student_id)?->student;; $examsrecordSingle =Student::find($student_id)?->examsrecord;; dd( $singleStudent, $examsrecordSingle); return view ('exams.registered_result',compact('singleStudent', 'examsrecordSingle')); There is a relation in the two Models above
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Transcript Preview</h1>
<a class="btn btn-primary" href="{{url('student/exams/pdf/'.$singleStudent->id)}}" role="button">View / Print Final Transcript</a>
</div>
@foreach ($examsrecordSingle as$student )
<tr> <td class="text-center">{{ $key+1 }}</td> <!--where to place subjects--> <td class="text-center">{{$student->exams_type}}</td> <td class="text-center">{{$student->exams_year}}</td> <td class="text-center">{{$student->subject_name}}</td> <td class="text-center">{{$student->exams_date}}</td> <td class="text-center">{{$student->obtained_marks }}</td> <td class="text-center">{{$student->grade}}</td> </tr> @endforeachAny help please ? Thanks in Advance
First, define a named route in your web.php:
Route::get('student/exams/pdf/{student}', 'StudentExamsController@printPDF')->name('student.exams.pdf');
Then, update your Blade template to use the route:
<a class="btn btn-primary" href="{{ route('student.exams.pdf', $singleStudent->id) }}" role="button">View / Print Final Transcript</a>
@if ($singleStudent) <a class="btn btn-primary" href="{{ route('student.exams.pdf', $singleStudent->id) }}" role="button">View / Print Final Transcript</a> @endif
And similarly, check before your foreach loop:
@if ($examsrecordSingle) @foreach ($examsrecordSingle as $key => $student) <!-- Table row --> @endforeach @endif
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community