Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add methods to determine if API resource has pivot loaded #46555

Merged
merged 1 commit into from
Mar 28, 2023
Merged

[10.x] Add methods to determine if API resource has pivot loaded #46555

merged 1 commit into from
Mar 28, 2023

Conversation

ziadoz
Copy link
Contributor

@ziadoz ziadoz commented Mar 23, 2023

I've refactored the trait code that checks if an API resource has a pivot here into a separate method, because it makes it easier to do complex checks in a Resource, which is something I've found myself needing to do:

$this->mergeWhen(
    $this->resource->field === 'whatever' && ! $this->resource->hasPivotLoaded('pivot_table'),
    ['foo' => 'bar'],
);

The changes here are covered by existing tests that use PostResourceWithOptionalPivotRelationship.

@taylorotwell taylorotwell merged commit 0fc5d30 into laravel:10.x Mar 28, 2023
@ziadoz ziadoz deleted the when-not-pivot-loaded branch March 29, 2023 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants