Skip to main content

Table Column: URL Link to Another Resource

Premium
2:34

The Full Lesson is Only for Premium Members

Want to access all of our courses? (31 h 16 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

S
safi ✓ Link copied!

wow, what a good course is that.. thanks a lot <3

I have a question because the foreign key "product_id" in table "payments" is not nullable() we can't delete a product that has a payment.. so in this situation what is the good practice:

  1. make the field "product_id" nullable() ?
  2. or make the products not deletable like users ?
PK
Povilas Korop ✓ Link copied!

Well spotted. There's actually no "good practice", it's a question to you as a project creator, or to your client who ordered this project. Personally, I love using Soft Deletes almost everywhere, just in case.

P
p-marco ✓ Link copied!

Great course, thanks. I am wondering: what about a multi-value column as in TagsColumn, where each record should be addressed via a url resource? Thanks

PK
Povilas Korop ✓ Link copied!

Not sure I understand the part of "addressed via a url resource", could you expand a bit more, or give a link to some project that already works this way? (or screenshot)

P
p-marco ✓ Link copied!

Thanks, Povilas! Let's imagine a similar scenario: we have a Post and an Attachment models based on their tables, and they have their linked relationship, so for example in PostResource we can have a TagColumn that shows each attachment for a singular post:

// PostResource.php
TagsColumn::make('attachment.slug')->separator(','),

So, how it could be possible to add a url method that can link to an AttachmentResource with a certain record? I hope it's clear :)

N
Nerijus ✓ Link copied!

Don't think this is possi in the core. You have to make a custom column. you can take TagsColumn as a starter and add what you need.

M�
Michal “Spil” Korol ✓ Link copied!

Is there any solution to open modal instead of url? I create fake column that pass record id to the controler that generate QR code for specific client in new tab. It works, but opening modal that will show the QR instead of new tab would be great.

TextColumn::make('qr')
                    ->label("Kod QR")
                    ->default('QR')
                    ->icon('heroicon-o-qr-code')
                    ->url(fn (Client $record): string => route('qrCode', ['id' => $record['id']]))
                    ->openUrlInNewTab()
                ,
N
Nerijus ✓ Link copied!

Maybe changing url to action and calling a custom modal would work. It would be best if you experimented with this to find the best approach. Maybe instead of clicking on a row just prepend an action button.

M�
Michal “Spil” Korol ✓ Link copied!

Thanks. I'll try. I just dont get to the point of building custom action for my app.