Updating record with custom action
i want to update data from another model with custom action, but the result always false(not updated), So far, this is what I've done. Function save is running smoothly btw
Solution:Jump to solution
```php
Schedule::updateOrCreate(
['ticket_header_ticket_id' => $ticket->ticket_id],
['schedule' => $data['schedule']]
)...
7 Replies
any suggestion guys ? what did i do wrong ?
$schedule->update()
will do nothing if you dont pass the attributes you want to update as an argument. Dont you mean ->save()
?previously I had an update function that ran smoothly.. like this..
I think the way I add attributes is the same, but it doesn't work in other actions, or is there another way to add attributes for updates?
there's no difference between
->save()
and ->update()
on your implementation, only the fact that its not working because you're not passing anything to ->update()
;
ok, let me try
sorry for stupid question, I'm still a beginner, in this case I want if there is a previous record from the $row results then update the record, if there isn't one then save a new record..
so is there a way to do like
$schedule->update(['schedule' => $data['schedule']])->where('schedule_id', $row->schedule_id);
and sorry for bad english.Solution
?
thanks @Saade , let me try first
it works! thanks again @Saade , i appreaciated your input. I use
updateOrCreate
function and adding unique field on migrations.