menu

Questions & Answers

How to select different registers in a table in a laravel view?

Here´s the thing. I have a view to show different students in a table. I`d like to select some of them, and send that to a method in my controller. Here is my table in the view:

<body style="background-color:#DEF5E5;">
       @auth
       <h1>Añade amigos de {{$student->name}}</h1>
       <table class="table">
         <thead style="background-color:#9ED5C5">
           <tr>
             <th>Nombre</th>
             <th>Apellidos</th>
             <th>Edad</th>
             <th>Opciones</th>
           </tr>
         </thead>
         <tbody>
             @foreach($students as $student)
                 <tr>
                     <td>{{$student->name}}</td>
                     <td>{{$student->surname}}</td>
                     <td>{{$student->age}}</td>
                     <td>
                     </td>
                 </tr>
             @endforeach
         </tbody>
       </table>
     </div>
    @endauth

    @guest
     <div class="container">
       <h1>Debes iniciar sesión</h1>
    @endguest

</body>
</html>

I'd like to select some of the registers, store them in and array or something like that and send that array to a method in my controller, but I don`t know how to select various rows and send them. Thank you.

Comments:
2023-01-20 23:30:10
One way would be to use a form around your table and checkboxes (with the row's student's ID as value f.e.) in each table row to select a register, then submit the form
Answers(0) :