Support the ongoing development of Laravel.io →
Blade Database Eloquent
0
  1. Use named routes instead of URLs directly as it makes your application easier to maintain and understand

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>

  1. In your Blade template, Handle Potential Null Objects

@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

  1. Check relations one more time to be sure it works, as expected
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Bashiro bashirosu Joined 14 Mar 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.