Halting the creation process

Not sure if Ive asked this before, but how is it possible to have a record before we create a record?
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

protected function beforeCreate(): void
{
if (! $this->getRecord()->team->subscribed()) {
Notification::make()
->warning()
->title('You don\'t have an active subscription!')
->body('Choose a plan to continue.')
->persistent()
->actions([
Action::make('subscribe')
->button()
->url(route('subscribe'), shouldOpenInNewTab: true),
])
->send();

$this->halt();
}
}
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification;

protected function beforeCreate(): void
{
if (! $this->getRecord()->team->subscribed()) {
Notification::make()
->warning()
->title('You don\'t have an active subscription!')
->body('Choose a plan to continue.')
->persistent()
->actions([
Action::make('subscribe')
->button()
->url(route('subscribe'), shouldOpenInNewTab: true),
])
->send();

$this->halt();
}
}
https://filamentphp.com/docs/3.x/panels/resources/creating-records#halting-the-creation-process
Solution:
before create you should use $this->data
Jump to solution
4 Replies
Matthew
Matthew3mo ago
When I do it, I get null :/
protected function beforeCreate(): void
{
dd($this->getRecord());
}
protected function beforeCreate(): void
{
dd($this->getRecord());
}
Solution
LeandroFerreira
LeandroFerreira3mo ago
before create you should use $this->data
Matthew
Matthew3mo ago
Why do the docs say getRecord()?
LeandroFerreira
LeandroFerreira3mo ago
it should be data at this point.. you could make a PR..