Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda