{$model->getKeyName()} = Uuid::uuid4()->toString(); }); // The rest of the app expects that data is a json string, all notification uses this format. // We need to exclude any spurious notification that does not have a valid json data static::addGlobalScope(new NotificationWithValidJson); } public static function rules($existing = null) { $required = Rule::requiredIf(function () use ($existing) { return $existing === null; }); $rules = [ 'notifiable_id' => [$required, 'integer'], 'notifiable_type' => [$required, 'string'], 'type' => [$required, 'string'], 'data' => [$required, 'string'], ]; return $rules; } }