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

Is it possible to get model relation in API service? #41

Open
jorbascrumps opened this issue Jul 11, 2022 · 0 comments
Open

Is it possible to get model relation in API service? #41

jorbascrumps opened this issue Jul 11, 2022 · 0 comments

Comments

@jorbascrumps
Copy link

If I define an Eloquent relationship on an API model am I able to get that relation in the API service?

Somewhere in app (ie, controller):

// App\Models\User
$author = Auth::find(1);

// Cristal\ApiWrapper\Bridges\Laravel\Model
$post = new Post([
    'title' => 'Untitled',
]);
$post->setRelation('author', $author);
$post->save();

API service:

public function createPost(array $attributes): array
{
    // Get author relation?
}

From what I can tell, models as a concept don't exist in the service and only attributes are available. If that's the case, what is the point of setting relations? Hope I'm missing something.

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

No branches or pull requests

1 participant