CristalTeam / php-api-wrapper

:rainbow: Work with APIs like with Laravel Eloquent or Doctrine (no longer a dream)
MIT License
117 stars 32 forks source link

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

Open jorbascrumps opened 2 years ago

jorbascrumps commented 2 years ago

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.