Lomkit / laravel-rest-api

Generate Api in seconds
https://laravel-rest-api.lomkit.com/
MIT License
444 stars 25 forks source link

Is this problem lifecycle? #97

Closed ThanhSonITNIC closed 8 months ago

ThanhSonITNIC commented 9 months ago

Description

If we create post with tags then post_id auto injection. it's ok

// PostResource
public function relations(\Lomkit\Rest\Http\Requests\RestRequest $request): array
{
    return [
        HasMany::make('tags', TagResource::class)->requiredOnCreation(),
    ];
}

When we create tag by api/tags/mutate we need post_id

// TagResource
public function createRules(\Lomkit\Rest\Http\Requests\RestRequest $request) {
    return [
        'post_id' => 'required',
    ];
}

But now, we create post with tags relation, post_id is required

GautierDele commented 9 months ago

Hello @ThanhSonITNIC can you confirm this is still the case with "2.4.2" please ? There was a lifecycle problem before I'll have a look after your confirmation to confirm this

ThanhSonITNIC commented 9 months ago

yes, 2.4.2

GautierDele commented 8 months ago

Ok @ThanhSonITNIC I think I got it, basically when you declare a relation, it's proper to the resource. It means that you need to put the "Post" relation on the tagResource "RequiredOnCreation" and not use createRules