F
Filament10mo ago
Damien

How do I correctly create a link to a record from another view?

I has various pages within the app I am building where I am displaying a list of items based on data being passed in. what I haven't been able to find in the docs yet though is how I can correctly link to one of the items being rendered so that it either navigates to the record view or opens up the view modal. Here is some example code with the todo comment being where I would like to action the link from
@foreach($this->data['products'] as $product)
<div class="flex items-center justify-between pt-4">
<div class="space-y-2">
<p class="font-semibold">{{ $product['name'] }}</p>
<p class="flex items-center text-gray-500">
<x-heroicon-s-calendar class="w-5 h-5 mr-1"/>
Updated: {{ date('d-m-Y H:i', strtotime($product['updated_at'] ?? $product['created_at'])) }}
</p>
</div>
<div>
{{-- TODO: Link to view record or view modal --}}
<x-filament::button>
Edit Product
</x-filament::button>
</div>
</div>
@endforeach
@foreach($this->data['products'] as $product)
<div class="flex items-center justify-between pt-4">
<div class="space-y-2">
<p class="font-semibold">{{ $product['name'] }}</p>
<p class="flex items-center text-gray-500">
<x-heroicon-s-calendar class="w-5 h-5 mr-1"/>
Updated: {{ date('d-m-Y H:i', strtotime($product['updated_at'] ?? $product['created_at'])) }}
</p>
</div>
<div>
{{-- TODO: Link to view record or view modal --}}
<x-filament::button>
Edit Product
</x-filament::button>
</div>
</div>
@endforeach
Apologies if this is an easy find, I struggled to do so and I couldn't find a similar thread in the forumn already.
Solution:
Turns out, it was in the docs all along and I was being stupid! I think I need this: ```php se App\Filament\Resources\CustomerResource; <x-filament::button tag="a" href="{{...
Jump to solution
8 Replies
Lara Zeus
Lara Zeus10mo ago
all pages can be accessed from the resource MyResource::getUrl('edit or view or any other page',['record=>1']);
Damien
DamienOP10mo ago
Ah nice! So for both of the resources I am trying to link to at the moment, they use a modal and a wizard for the create / edit actions so there is not a dedicated page. Does this have to change or is there a way to action the modals?
Lara Zeus
Lara Zeus10mo ago
ya I dont think so the modals and it's actions lives in the resource maybe you could refactor that, extract the action and reuse it as an action in other places
Damien
DamienOP10mo ago
Interesting, thank you Lara, I will have a look and a play.
Solution
Damien
Damien10mo ago
Turns out, it was in the docs all along and I was being stupid! I think I need this:
se App\Filament\Resources\CustomerResource;
<x-filament::button tag="a" href="{{
\App\Filament\Resources\ProjectResource::getUrl(parameters: [
'action' => \Filament\Actions\CreateAction::getDefaultName(),
])
}}">
New Project
</x-filament::button>
se App\Filament\Resources\CustomerResource;
<x-filament::button tag="a" href="{{
\App\Filament\Resources\ProjectResource::getUrl(parameters: [
'action' => \Filament\Actions\CreateAction::getDefaultName(),
])
}}">
New Project
</x-filament::button>
Will come back and confirm.
Damien
DamienOP10mo ago
So creating a new record works correctly but when I try and edit a record, it doesn't open the modal, here is the code for the edit
<x-filament::button tag="a" href="{{
\App\Filament\Resources\ProjectResource::getUrl(parameters: [
'action' => \Filament\Actions\EditAction::getDefaultName(),
'record' => $project,
])
}}">
Edit Project
</x-filament::button>
<x-filament::button tag="a" href="{{
\App\Filament\Resources\ProjectResource::getUrl(parameters: [
'action' => \Filament\Actions\EditAction::getDefaultName(),
'record' => $project,
])
}}">
Edit Project
</x-filament::button>
I have updated the first example to match my code. If I try the table version
<div>
<x-filament::button tag="a" href="{{
\App\Filament\Resources\StockProductResource::getUrl(parameters: [
'tableAction'=> \Filament\Tables\Actions\EditAction::getDefaultName(),
'tableActionRecord' => $product,
])
}}">
Edit
</x-filament::button>
</div>
<div>
<x-filament::button tag="a" href="{{
\App\Filament\Resources\StockProductResource::getUrl(parameters: [
'tableAction'=> \Filament\Tables\Actions\EditAction::getDefaultName(),
'tableActionRecord' => $product,
])
}}">
Edit
</x-filament::button>
</div>
It navigates to the products but it does not open the edit modal. The URL very quickly flashes to, from http://localhost:8080/stock-products?tableAction=edit&tableActionRecord=1 to just http://localhost:8080/stock-products
toeknee
toeknee10mo ago
Not sure but a thought would be to include the filament-modals blade?
Damien
DamienOP10mo ago
oh okay, so add <x-filament::modal /> to the blade file? syntax is likely wrong there, I was guessing. This didn't seem to do the trick. I fixed it. Need to have the table action present in the actions array.
Want results from more Discord servers?
Add your server