How can i send a message to a component that will be processed in a foreach

  html-table, laravel, laravel-8, php

I have this in my view:

            <x-general.table :dataArray="$pacientes" :titlesArray="$titlesArray">
            <x-slot name="actionsRow">
                <a href="{{ url('/pacientes/' . $dataArray->id . '/edit') }}">
                <form action="{{ url('/pacientes/' . $dataArray->id) }}" method="post">
                    {{ method_field('DELETE') }}
                    <input type="submit" value="Borrar"
                           onclick="return confirm('Quieres borrar este registro?')">

I need to get the data in the array dataArray->id later in the component slot actionsRow:

<table class="rounded-t-lg m-5 w-5/6 mx-auto bg-gray-200 text-gray-800">
<thead class="text-left border-b-2 border-gray-300">
@foreach(array_keys($titlesArray) as $titles)
    <th class="px-4 py-3">{{ $titles }}</th>
@if (count($dataArray)>0)
    @foreach($dataArray as $data)
        <tr class="bg-gray-100 border-b border-gray-200">
            @foreach(array_values($titlesArray) as $td)
                <td class="px-4 py-3">{{$data->$td}}</td>
                @php $id = $data->id @endphp
                {{ $actionsRow }}

It’s giving me an undefined variable Error. How can i achieve this?, i don’t want to put this actions inside the component, because i will reuse this same table for other views with different data and different actions for each row.

Source: Laravel

Leave a Reply