Updating a text input after dispatching a job

Section::make('Originality Check')
->schema([
Forms\Components\TextInput::make('originality_check_result')
->label('Originality Check Result')
->live()
->disabled()
->default(fn ($record) => $record ? json_encode($record->originality_check_result) : null),
Forms\Components\Actions::make([
Action::make('checkOriginality')
->label('Check Originality')
->action(function ($livewire) {
$record = $livewire->form->getRecord();
self::dispatchOriginalityCheckJob($record);

}),
]),
])
Section::make('Originality Check')
->schema([
Forms\Components\TextInput::make('originality_check_result')
->label('Originality Check Result')
->live()
->disabled()
->default(fn ($record) => $record ? json_encode($record->originality_check_result) : null),
Forms\Components\Actions::make([
Action::make('checkOriginality')
->label('Check Originality')
->action(function ($livewire) {
$record = $livewire->form->getRecord();
self::dispatchOriginalityCheckJob($record);

}),
]),
])
The dispatchOriginalityCheckJob is updating the current article's originality_check_result field to the correct value, but it's not being reflected live on the form itself. Can I somehow force this 'refresh'?
6 Replies
LeandroFerreira
LeandroFerreira6mo ago
Did you try injecting Set $set? $set('originality_check_result', 'xx')
prowler
prowlerOP6mo ago
Yes. i tried it like this but it didn't help -
Forms\Components\Actions::make([
Action::make('checkOriginality')
->label('Check Originality')
->action(function ($livewire, Forms\Set $set) {
$record = $livewire->form->getRecord();
self::dispatchOriginalityCheckJob($record);
$set('originality_check_result', $record->originality_check_result);
})
])
Forms\Components\Actions::make([
Action::make('checkOriginality')
->label('Check Originality')
->action(function ($livewire, Forms\Set $set) {
$record = $livewire->form->getRecord();
self::dispatchOriginalityCheckJob($record);
$set('originality_check_result', $record->originality_check_result);
})
])
the originality_check_result is being updated in the background, so it reaches the $set method before the job is finished..
LeandroFerreira
LeandroFerreira6mo ago
hum..
prowler
prowlerOP6mo ago
does it mean i need to think of some real-time solution with broadcasting and such? if only i could return a value from the dispatched job itself and then put in inside the $set i mean, i can always remove Illuminate\Bus\Queueable from the job and then be able to return data from my handle method, but im not sure its an elegant solution..
dissto
dissto6mo ago
How complex is your dispatchOriginalityCheckJob ? Does it warrant the extra complexity or could you do that simply (if its a simple operation) inline and immediately get the result back to set it properly? 🤔
prowler
prowlerOP6mo ago
i compromised and gave up the asynchronicity simply using ->dispatchSync() and setting the value right away. -
Forms\Components\Actions::make([
Action::make('checkOriginality')
->label('Check Originality')
->action(function ($livewire, Forms\Set $set) {
$record = $livewire->form->getRecord();
$result = self::dispatchOriginalityCheckJob($record);
$set('originality_check_result', implode(",",$result));
})
])
Forms\Components\Actions::make([
Action::make('checkOriginality')
->label('Check Originality')
->action(function ($livewire, Forms\Set $set) {
$record = $livewire->form->getRecord();
$result = self::dispatchOriginalityCheckJob($record);
$set('originality_check_result', implode(",",$result));
})
])
and dispatchOriginalityCheckJob() is now -
protected static function dispatchOriginalityCheckJob($record)
{
$result = OriginalityCheckJob::dispatchSync($record);

Notification::make()
->title("Originality Check Job Dispatched")
->body("The article content is being checked for originality.")
->success()
->send();

return $result;
}
protected static function dispatchOriginalityCheckJob($record)
{
$result = OriginalityCheckJob::dispatchSync($record);

Notification::make()
->title("Originality Check Job Dispatched")
->body("The article content is being checked for originality.")
->success()
->send();

return $result;
}
thank you both @dissto and @Leandro Ferreira !!
Want results from more Discord servers?
Add your server