diff --git a/composer.json b/composer.json index c91da6c..2bcea88 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fleetbase/core-api", - "version": "1.1.2-alpha", + "version": "1.1.3-alpha", "description": "Core Framework and Resources for Fleetbase API", "keywords": [ "fleetbase", diff --git a/src/Casts/PolymorphicType.php b/src/Casts/PolymorphicType.php index bed92a9..c031848 100644 --- a/src/Casts/PolymorphicType.php +++ b/src/Casts/PolymorphicType.php @@ -32,7 +32,12 @@ public function get($model, $key, $value, $attributes) */ public function set($model, $key, $value, $attributes) { - $className = Utils::getMutationType($value); + // default $className is null + $className = null; + + if ($value) { + $className = Utils::getMutationType($value); + } return $className; } diff --git a/src/Support/Utils.php b/src/Support/Utils.php index a9441bb..bb7e7ba 100644 --- a/src/Support/Utils.php +++ b/src/Support/Utils.php @@ -76,11 +76,10 @@ public static function consoleUrl(string $path, ?array $queryParams = null, $sub */ public static function fromS3(string $path, $bucket = null, $region = null): string { - $bucket = $bucket ?? config('filesystems.disks.s3.bucket'); - $region = $region ?? config('filesystems.disks.s3.region'); + $bucket = $bucket ?? config('filesystems.disks.s3.bucket', $bucket); + $region = $region ?? config('filesystems.disks.s3.region', $region); return 'https://' . $bucket . '.s3-' . $region . '.amazonaws.com/' . $path; - // return 'https://s3.' . $region . '.amazonaws.com/' . $bucket . '/' . $path; } /** @@ -90,9 +89,21 @@ public static function fromS3(string $path, $bucket = null, $region = null): str * @param string $pattern * @return boolean */ - public static function assetFromS3(string $path): string + public static function assetFromS3(string $path, $region = null): string { - return static::fromS3($path, 'flb-assets'); + return static::fromS3($path, 'flb-assets', $region); + } + + /** + * Return asset URL from Fleetbase S3 asset bucket. + * + * @param string $string + * @param string $pattern + * @return boolean + */ + public static function assetFromFleetbase(string $path): string + { + return static::assetFromS3($path, 'ap-southeast-1'); } /** diff --git a/src/Traits/HasApiModelBehavior.php b/src/Traits/HasApiModelBehavior.php index d37d108..0d82fdf 100644 --- a/src/Traits/HasApiModelBehavior.php +++ b/src/Traits/HasApiModelBehavior.php @@ -942,7 +942,8 @@ public function isInvalidUpdateParam(string $key): bool $isNotRelation = !$this->isRelation($key) && !$this->isRelation(Str::camel($key)); $isNotFilterParam = !$this->isFilterParam($key); $isNotAppenededAttribute = !in_array($key, $this->appends ?? []); + $isNotIdParam = !in_array($key, ['id', 'uuid', 'public_id']); - return $isNotTimestamp && $isNotFillable && $isNotRelation && $isNotFilterParam && $isNotAppenededAttribute; + return $isNotTimestamp && $isNotFillable && $isNotRelation && $isNotFilterParam && $isNotAppenededAttribute && $isNotIdParam; } }