Passing data to custom page through table action.

Hi, I'm trying to pass the current record to a custom page on a table action, however I can't seem to get the data. Here's my setup: Layer resource, table actions:
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('draw')
->label('Draw')
->url(fn (Layer $record): string => route('filament.resources.layers.draw', ['record' => $record]))
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('draw')
->label('Draw')
->url(fn (Layer $record): string => route('filament.resources.layers.draw', ['record' => $record]))
])
Draw custom page blade view:
<x-filament::page>
<div id="map">
@dd($record)
</div>
</x-filament::page>
<x-filament::page>
<div id="map">
@dd($record)
</div>
</x-filament::page>
Error:
Undefined variable $record
Undefined variable $record
. I can't find much on the docs. Any clues as to what might be going wrong?
10 Replies
Dennis Koch
Dennis Koch2y ago
Add $record as a public property to your page
Kanalaetxebarria
KanalaetxebarriaOP2y ago
Already tried that! Comes however I declared it (so either null or an empty array or however I declare it), without the actual record
public $record;
public $record;
Dump:
null // resources/views/filament/resources/layer-resource/pages/draw-hotspots.blade.php
null // resources/views/filament/resources/layer-resource/pages/draw-hotspots.blade.php
Dennis Koch
Dennis Koch2y ago
Tried $this->record?
Kanalaetxebarria
KanalaetxebarriaOP2y ago
Same output :/
Dennis Koch
Dennis Koch2y ago
Can you share the code for your page?
Kanalaetxebarria
KanalaetxebarriaOP2y ago
It's what was generated by the filament make page command:
<?php

namespace App\Filament\Resources\LayerResource\Pages;

use App\Filament\Resources\LayerResource;
use Filament\Resources\Pages\Page;

class DrawHotspots extends Page
{
protected static string $resource = LayerResource::class;

protected static string $view = 'filament.resources.layer-resource.pages.draw-hotspots';

public $record;
}
<?php

namespace App\Filament\Resources\LayerResource\Pages;

use App\Filament\Resources\LayerResource;
use Filament\Resources\Pages\Page;

class DrawHotspots extends Page
{
protected static string $resource = LayerResource::class;

protected static string $view = 'filament.resources.layer-resource.pages.draw-hotspots';

public $record;
}
Dennis Koch
Dennis Koch2y ago
I thought that should be enough. But maybe it was another component. This should work:
use InteractsWithRecord;

public function mount($record)
{
$this->record = $this->resolveRecord($record);
}
use InteractsWithRecord;

public function mount($record)
{
$this->record = $this->resolveRecord($record);
}
Actually this should be enough:
public YourModel $record;
public YourModel $record;
You need to type hint it.
Kanalaetxebarria
KanalaetxebarriaOP2y ago
Great!! Type hinting worked, thanks!
aliaxon
aliaxon15mo ago
No description
aliaxon
aliaxon15mo ago
Having same issue: I'm trying to pass data from a filament resource using custom action: ActionsAction::make('view') ->label('Details') ->url(fn (MyQuizzes $record): string => route('filament.member.pages.quiz-detail-page', $record)), The data I want to deliver is to a custom livewire component within custom page: Custom Page view: <x-filament-panels::page> <livewire:QuizDetailPage/> </x-filament-panels::page> Any help in the right direction would be highly apprecated!
Want results from more Discord servers?
Add your server