Why is my $record->save(); not working

Should I expect one of these to save the current record?
Action::make('Run Campaign')
->action(function (Campaign $record, Set $set) {
$set('status_id', CampaignStatusEnum::Run );
$record->save();
}),
Action::make('Run Campaign')
->action(function (Campaign $record, Set $set) {
$set('status_id', CampaignStatusEnum::Run );
$record->save();
}),
Or
Action::make('Pause Campaign')
->action(function (?Model $record, Set $set) {
$set('status_id', CampaignStatusEnum::Paused );
$record->save();
})
Action::make('Pause Campaign')
->action(function (?Model $record, Set $set) {
$set('status_id', CampaignStatusEnum::Paused );
$record->save();
})
The field changes on the scren but is not save.
Solution:
in your case if you want to update the model you need to do ```php Action::make('Pause Campaign') ->action(function (?Model $record) {...
Jump to solution
6 Replies
Dennis Koch
Dennis Koch6mo ago
Because you don’t change the data of your record 🤔 $set is a helper for the form data. Not for Laravel models.
Solution
Tieme
Tieme6mo ago
in your case if you want to update the model you need to do
Action::make('Pause Campaign')
->action(function (?Model $record) {
$record->status_id = CampaignStatusEnum::Paused;
$record->save();
})
Action::make('Pause Campaign')
->action(function (?Model $record) {
$record->status_id = CampaignStatusEnum::Paused;
$record->save();
})
ddoddsr
ddoddsrOP6mo ago
I tried both of those and they don't save. Am I missing something else?
awcodes
awcodes6mo ago
Try
$record->update([
‘status_id’ => CampaignStatusEnum::Paused
])
$record->update([
‘status_id’ => CampaignStatusEnum::Paused
])
Dennis Koch
Dennis Koch6mo ago
Both of what? I explained why both of your examples don’t work and Tieme only shared one example which definitely should work?!
ddoddsr
ddoddsrOP6mo ago
My bad, I re-read your first comment and Tieme first comment and realized that I mis-read. Both explaination where helpful and It is working as needed.
Want results from more Discord servers?
Add your server