Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
Fetch all the rows with same column number in laravel

I have a modal button associated with each student on a table. When I press the button I want to be able to fetch all results associated with the admission_num from another table. The code I have is below.

enter image description here

Here is my controller code

public function view_student_result($id)
{

    $user= User::where('admission_num', $id)->get();
    
    $resultdata = juniorResults::where('admission_num', $id)->get();



    return view('backend.student_result_view', compact('resultdata', 'user'));
}

Here is my route

Route::get('view-student-result/{id}', [viewResultController::class, 'view_student_result'])->name('view_student_result');

Here is the button that links to the view result page

  <a href="{{ route('view_student_result', $studentDatas->admission_num) }}"><i class="fas fa-print"></i></a>

When I used get(), I got this error Property [admission_num] does not exist on this collection instance. But when I use first() instead of get() the code was able to fetch just one result. below is the dd(collection)

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

To get all students with a specific Admission_num, you can use this statement:

$resultdata = juniorResults::where('Admission_num', 12345)->get();

Small hint: Instead of writing your url by hand, it is safer to use the name of your route:

<a href="{{ route('view_student_result', $studentDatas['id']) }}"></a>
about 4 years ago · Juan Pablo Isaza Report

0

If you want all rows you dont have to use first(). Instead of first what you returns only the first userobject you have to use all() or get. $user= User::where('admission_num', $id)->get();

small note You screenshot from you database table admission_num is upper case the first letter. And in your eloquent query you have lower case.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!