Jordy
Jordy
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Export ChartWidget to image
this might be the worst code I've ever written, but I ended up building the chart in a livewire component, and then sending the image to the backend inside a script tag
@script
<script>
Livewire.dispatch('saveImage', {base64: chart{{ $product->name }}.toBase64Image('image/png', 1)});
</script>
@endscript
@script
<script>
Livewire.dispatch('saveImage', {base64: chart{{ $product->name }}.toBase64Image('image/png', 1)});
</script>
@endscript
Issues I encountered: image would be empty if I didnt disable animations or set a timeout (this sucks, so i disabled entirely)https://www.chartjs.org/docs/latest/configuration/animations.html Had quite some issues getting chartjs to work (I needed it outside of the filament panel aswell, so I ended up using this package which works pretty well. If you give the charts a unique name you can easily fetch them with JS using their name. https://icehouse-ventures.github.io/laravel-chartjs/
3 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
cheers.. now this works.. I need to find a way to turn the chart into an image or somehow slap it in a pdf
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
smh :kekw:
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
wtf it works now
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
it would throw $record must not be accessed before initialization
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
like this
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
the page
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
public function getWidgetData(): array
{
return [
'record' => $this->record,
];
}
public function getWidgetData(): array
{
return [
'record' => $this->record,
];
}
throws $record must not be accessed before initialization (I try to dd it in getData) worth nothing I only call the widget in the view.. havent registered it on the actual page
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
No description
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
...my coffee just kicked in, the page was already using route model binding.. so why not just pull it from the route 🤦‍♂️
protected function getData(): array
{
$record = request()->route('record');

....
}
protected function getData(): array
{
$record = request()->route('record');

....
}
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
my fix doesnt work either since getData() seems the be ran before mount()
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
yes
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
have another issue which is getting the chart in the pdf I want to export but thats a different issue kek
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
inside the view of a page
<@php use App\Filament\Resources\Management\ProductResource\Widgets\GrainChart; @endphp
<x-filament-panels::page>
<x-filament::section>
<x-pdf.product-information-sheet :product="$this->record"/>
</x-filament::section>
@livewire(GrainChart::class)
//Would like to pass the record like:
//@livewire(GrainChart::class, ['record' => $this->record]);
</x-filament-panels::page>
<@php use App\Filament\Resources\Management\ProductResource\Widgets\GrainChart; @endphp
<x-filament-panels::page>
<x-filament::section>
<x-pdf.product-information-sheet :product="$this->record"/>
</x-filament::section>
@livewire(GrainChart::class)
//Would like to pass the record like:
//@livewire(GrainChart::class, ['record' => $this->record]);
</x-filament-panels::page>
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
assuming because its a widget, not a page
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
same issue :/
36 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
this would throw $record must not be accessed before initialization if used in getData()
36 replies
FFilament
Created by Pierrot on 1/2/2025 in #❓┊help
Table must not be accessed before initialization
you dont really need $this for your form,nor do you need the entire form for your action, just the schema
6 replies
FFilament
Created by Pierrot on 1/2/2025 in #❓┊help
Table must not be accessed before initialization
likely has to do with $this->makeForm()->getComponents() which you call when you make your action I'd refactor your makeForm() method to just return an array of components
private static function getFormComponents(?params): array
{
return [
TextInput::make(),
...
];
}
private static function getFormComponents(?params): array
{
return [
TextInput::make(),
...
];
}
6 replies
FFilament
Created by Jordy on 1/2/2025 in #❓┊help
Passing a record to a chart
can throw this in a PR if it indeed doesnt break anything..
36 replies