-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathCreateUpdate.php
More file actions
30 lines (24 loc) · 855 Bytes
/
CreateUpdate.php
File metadata and controls
30 lines (24 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace Cachet\Actions\Update;
use Cachet\Data\Requests\IncidentUpdate\CreateIncidentUpdateRequestData;
use Cachet\Data\Requests\ScheduleUpdate\CreateScheduleUpdateRequestData;
use Cachet\Events\Incidents\IncidentUpdated;
use Cachet\Models\Incident;
use Cachet\Models\Schedule;
use Cachet\Models\Update;
class CreateUpdate
{
/**
* Handle the action.
*/
public function handle(Incident|Schedule $resource, CreateIncidentUpdateRequestData|CreateScheduleUpdateRequestData $data): Update
{
$update = new Update(array_merge(['user_id' => auth()->id()], $data->toArray()));
$resource->updates()->save($update);
if($resource instanceof Incident) {
$resource->update(['status' => $update->status]);
IncidentUpdated::dispatch($resource);
}
return $update;
}
}