Custom widget, passing variables to blade

I'm trying to make a custom widget (all other widgets works) class
<?php
namespace App\Filament\Resources\RepairResource\Widgets;

use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;

class RepairOverview2 extends Widget
{
protected static string $view = 'filament.resources.repair-resource.widgets.repair-overview2';
public ?Model $record = null;
protected int|string|array $columnSpan = 'full';


}
<?php
namespace App\Filament\Resources\RepairResource\Widgets;

use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;

class RepairOverview2 extends Widget
{
protected static string $view = 'filament.resources.repair-resource.widgets.repair-overview2';
public ?Model $record = null;
protected int|string|array $columnSpan = 'full';


}
blade
<x-filament-widgets::widget>
<x-filament::section>
{{-- Widget content --}}

{{ $record->quote }} this works <---
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-5 dark:bg-inherit">
<div class="p-4 rounded-lg shadow">
<h3 class="text-lg font-semibold">Quote</h3>
<p class="text-2xl">{{ $quote }} €</p>
</div>
</div>
</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
{{-- Widget content --}}

{{ $record->quote }} this works <---
<div class="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-5 dark:bg-inherit">
<div class="p-4 rounded-lg shadow">
<h3 class="text-lg font-semibold">Quote</h3>
<p class="text-2xl">{{ $quote }} €</p>
</div>
</div>
</x-filament::section>
</x-filament-widgets::widget>
$record in template works but i want to prepare the variable in my class and then send it to the tpl but i tried several options, like mount, getData... no one works.
Solution:
solution ``` public array $data = []; // Quote private function getQuote(): float...
Jump to solution
1 Reply
Solution
Soundmit
Soundmit6mo ago
solution
public array $data = [];
// Quote
private function getQuote(): float
{
$quote = 0.0;

if ($this->record->parts) {
foreach ($this->record->parts as $part) {
$quote += intval($part['qt']) * floatval($part['selling_price']);
}
}
return round($quote, 2);
}
...
public function mount(): void
{
$this->data = [
'quote' => $this->getQuote(),
];
}
public array $data = [];
// Quote
private function getQuote(): float
{
$quote = 0.0;

if ($this->record->parts) {
foreach ($this->record->parts as $part) {
$quote += intval($part['qt']) * floatval($part['selling_price']);
}
}
return round($quote, 2);
}
...
public function mount(): void
{
$this->data = [
'quote' => $this->getQuote(),
];
}
Want results from more Discord servers?
Add your server