Files
fewo-stommer/app/Actions/SaveChannelRules.php
T
2026-10-27 19:00:25 +01:00

22 lines
600 B
PHP

<?php
namespace App\Actions;
use App\Channels\ICal\ICalRuleEngine;
use App\Models\Channel;
use Illuminate\Support\Facades\DB;
class SaveChannelRules
{
public function handle(Channel $channel, array $rules): Channel
{
return DB::transaction(function () use ($channel, $rules): Channel {
$locked = Channel::query()->whereKey($channel->id)->lockForUpdate()->firstOrFail();
$validated = app(ICalRuleEngine::class)->validate($locked, $rules);
$locked->forceFill(['ical_rules' => $validated])->save();
return $locked;
});
}
}