Notifying the user after dispatching a background job once creating a new entry.

Right now im tackling it from the model's pov .. in Brief.php i have this part of code -
protected static function booted()
{
static::created(function ($brief) {
GenerateContentForBrief::dispatch($brief);
});
}
protected static function booted()
{
static::created(function ($brief) {
GenerateContentForBrief::dispatch($brief);
});
}
The job itself is doing bunch of things and eventually creates a new Article entry.. How can i notify the user in filament that their job is done? (Right now im using database driver for my jobs)
6 Replies
prowler
prowlerOP8mo ago
didn't work for me for some reason .. no errors whatsoever, but no notfications as well
LeandroFerreira
LeandroFerreira8mo ago
php artisan queue:work ?
prowler
prowlerOP8mo ago
already runs.. i'll keep on trying. shouldn't i pro-actively do some $user->notify(...) thingy?
prowler
prowlerOP8mo ago
oh! thanks! btw, @Leandro Ferreira , a bit unrelated, but maybe u can help as well - on the created function from before - is there an option to retrieve the relationship too? i guess those are created after the model itself is created, but changing the event to saved didn't help me neither loading the relationship actively ($brief->load('sections')) .. The Brief model has a hasMany relationship with the Section model and im creating it with a filament repeater -
Section::make('Brief Sections')
->description('Add all brief sections')
->schema([
Repeater::make('sections')
->columnSpanFull()
->relationship('sections')
->schema([
Forms\Components\Textarea::make('name')
->required()
->columnSpanFull(),
Forms\Components\Textarea::make('specific_instructions')
->columnSpanFull(),
Forms\Components\TextInput::make('words_count')
->numeric()
->default(0),
Forms\Components\Toggle::make('is_expandable')
->required(),
]),
]),

]);
Section::make('Brief Sections')
->description('Add all brief sections')
->schema([
Repeater::make('sections')
->columnSpanFull()
->relationship('sections')
->schema([
Forms\Components\Textarea::make('name')
->required()
->columnSpanFull(),
Forms\Components\Textarea::make('specific_instructions')
->columnSpanFull(),
Forms\Components\TextInput::make('words_count')
->numeric()
->default(0),
Forms\Components\Toggle::make('is_expandable')
->required(),
]),
]),

]);
But then, on the model's created (or saved) event(s) i get an empty array when trying to access $brief->sections.. for example (using saved method along with the attempt to load the relationship actively) -
protected static function booted()
{
static::saved(function ($brief) {
$brief->load('sections');
dd($brief->sections);
});
}
protected static function booted()
{
static::saved(function ($brief) {
$brief->load('sections');
dd($brief->sections);
});
}
I guess its more laravel-related, but just making sure its not something i'm missing the filament way well, never mind, i solved it via filament's afterCreate() method
Want results from more Discord servers?
Add your server