Files
fewo-stommer/app/Models/Concerns/HasChannelProvenance.php
T
Lars 783068501c
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m33s
Generische iCal-Kanäle mit Bestandsklärung und sicheren Exporten bereitstellen
2026-10-27 17:14:45 +01:00

23 lines
763 B
PHP

<?php
namespace App\Models\Concerns;
use App\Models\Channel;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\ValidationException;
trait HasChannelProvenance
{
public static function bootHasChannelProvenance(): void
{
static::saving(function (Model $model): void {
foreach (['channel_id', 'import_channel_id', 'origin_channel_id'] as $field) {
$id = $model->getAttribute($field);
if ($id !== null && ! Channel::withoutGlobalScope('tenant')->whereKey($id)->where('property_id', $model->property_id)->exists()) {
throw ValidationException::withMessages([$field => 'Der Kanal muss zur selben Wohnung gehören.']);
}
}
});
}
}