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? (36 h 00 min)

You also get:

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

Already a member? Login here

safi avatar

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 ?
Povilas Korop avatar

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.

😍 1
p-marco avatar

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

Povilas Korop avatar

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-marco avatar

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 :)

Nerijus avatar

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.

Michal “Spil” Korol avatar
Michal “Spil” Korol

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()
,
Nerijus avatar

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.

Michal “Spil” Korol avatar
Michal “Spil” Korol

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