Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vicl940303's avatar

Show card in hasmany

I have in resource Client HasMany::make(__('Bills'), 'payBills', PayBill::class), And the resource PayBill has a card (new InvoiceCard) I need to show this card on relationship hasMany, i need to see it in detail of Client, only show the table, but not the card.

0 likes
1 reply
LaryAI's avatar
Level 58

To show the card for the PayBill resource in the Client detail view, you can customize the HasMany relationship view. In your Client resource file, you can add a method called payBillsTable that returns a view with the table of PayBills and the InvoiceCard. Here's an example:

use App\Nova\Resource;
use Laravel\Nova\Fields\HasMany;

class Client extends Resource
{
    // ...

    public function fields(Request $request)
    {
        return [
            // ...
            HasMany::make(__('Bills'), 'payBills', PayBill::class)
                ->tableColumns([
                    // add columns for the PayBill table
                    // ...
                ])
                ->viewable(function ($resource, $attribute, $column, $value) {
                    // customize the view for each PayBill row
                    return view('pay-bills-table-row', [
                        'payBill' => $resource,
                        'invoiceCard' => new InvoiceCard($resource),
                    ]);
                }),
        ];
    }

    public function payBillsTable()
    {
        $payBills = $this->payBills;

        return view('pay-bills-table', [
            'payBills' => $payBills,
            'invoiceCard' => new InvoiceCard($this),
        ]);
    }
}

In this example, we're using the viewable method to customize the view for each row of the PayBill table. We're also adding a new method called payBillsTable that returns a view with the table and the InvoiceCard. You can customize the views as needed to match your design.

Then, create the pay-bills-table.blade.php and pay-bills-table-row.blade.php views in your resources/views directory. Here's an example of what the pay-bills-table.blade.php view might look like:

<table>
    <thead>
        <tr>
            <th>PayBill ID</th>
            <th>Amount</th>
            <th>Invoice Card</th>
        </tr>
    </thead>
    <tbody>
        @foreach ($payBills as $payBill)
            @include('pay-bills-table-row', ['payBill' => $payBill])
        @endforeach
    </tbody>
</table>

And here's an example of what the pay-bills-table-row.blade.php view might look like:

<tr>
    <td>{{ $payBill->id }}</td>
    <td>{{ $payBill->amount }}</td>
    <td>{!! $invoiceCard->render() !!}</td>
</tr>

This will render the InvoiceCard for each PayBill row in the table.

Please or to participate in this conversation.