Skip to content

Commit d4438af

Browse files
committed
Remote models hydrated from API
Remote models created from API responses now have their exists flag set to true, preventing Laravel from querying the local database for them
1 parent 5be672c commit d4438af

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Changed
1818
- Refactored `QueryBuilder` and `ApiModel` to use the new `ParsesApiResponse` trait, removing duplicate `parseResponse` implementations.
1919

20+
### Fixed
21+
- Remote models hydrated from API responses are marked as existing to prevent local database queries.
2022

2123
## [0.4.1] - 2025-07-10
2224
### Added

src/Traits/ApiModelTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static function fromApiResponse(array $data): static
2424
{
2525
$instance = new static();
2626

27+
// Handle API relations defined in the model
2728
foreach (static::$apiRelations as $relation => $cast) {
2829
if (array_key_exists($relation, $data)) {
2930
$instance->setRelation(
@@ -34,8 +35,14 @@ public static function fromApiResponse(array $data): static
3435
}
3536
}
3637

38+
// Fill the model with the remaining data
3739
$instance->fill($data);
3840

41+
// Mark the instance as existing to prevent local database queries
42+
if (property_exists($instance, 'exists')) {
43+
$instance->exists = true;
44+
}
45+
3946
return $instance;
4047
}
4148

0 commit comments

Comments
 (0)