F
Filament14mo ago
πTeR

It is possible do use __construct on Edit Page?

I'm using a service on a __construct inside a create page, and it is working like a charm. But when I use it in a EditPage, I have this error message Target [App\Http\Services\PaymentTransaction\PaymentTransactionServiceContract] is not instantiable while building [App\Filament\Resources\PaymentIntentionResource\Pages\EditPaymentIntention].
Solution:
Ok I tryed it: ```php public function mount(int|string $record): void {...
Jump to solution
2 Replies
awcodes
awcodes14mo ago
Are you using panels? If so the page is the livewire component and you should be handling the logic in mount() and not __construct()
Solution
πTeR
πTeR14mo ago
Ok I tryed it:
public function mount(int|string $record): void
{
parent::mount($record);
$this->paymentTransactionService = app()->make(PaymentTransactionServiceContract::class);
}
public function mount(int|string $record): void
{
parent::mount($record);
$this->paymentTransactionService = app()->make(PaymentTransactionServiceContract::class);
}
But it still not working, and I solved using app()->make() directly on beforeSave() method.. Something like this:
protected function beforeSave(): void
{
app()->make(PaymentTransactionServiceContract::class)->createTransaction($this->data, $this->getRecord());
}
protected function beforeSave(): void
{
app()->make(PaymentTransactionServiceContract::class)->createTransaction($this->data, $this->getRecord());
}
Nice hint @awcodes 🙏
Want results from more Discord servers?
Add your server