Skip to content

Commit

Permalink
New utility functions and patches
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Jul 10, 2023
1 parent d0715ae commit 6551b4a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/Casts/PolymorphicType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 16 additions & 5 deletions src/Support/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Traits/HasApiModelBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 6551b4a

Please sign in to comment.