Courses

Laravel Filament Admin v2: Practical Course

Table Column: URL Link to Another Resource

Previous: Date Filters for Payment From/Until
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 ?
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.

avatar
You can use Markdown
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

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)

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

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.

avatar
You can use Markdown
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()
                ,
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.

avatar
Michal “Spil” Korol

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

avatar
You can use Markdown
avatar
You can use Markdown