I need make an api with laravel 5.7, the api is not a problem itself.
I need make a strict validation for the current model and nested relations objects for save, example.
Imagine a model Posts with a relation comments. I have stored my data in database as:
[
{id: 1, user_id: 1, title: 'my title post', comments: [{id: 5, comment: 'my comment for post id 1'}]},
{id: 2, user_id: 1, title: 'my second title post', comments: [{id: 15, comment: 'my comment for post id 2'}]},
{id: 8, user_id: 2, title: 'my third title post', comments: [{id: 25, comment: 'my comment for post id 8'}]}
]
My user_id logged in the api is 1
If I try send a POST http to update a post and a comment how I can validate the user logged in the api is the owner of each object? example of post:
POST to update.
[
{id: 1, user_id: 1, title: 'my title post modified', comments: [{id: 5, comment: 'my comment for post id 1'}]},
{id: 1, user_id: 1, title: 'my title post modified 2', comments: [{id: 25, comment: 'my comment for post id 1'}]},
{`id: 8`, user_id: 2, title: 'my title post', comments: [{`id: 25`, comment: 'my comment for post id 1'}]},
]
how example show, I can modify only the first and second object of my array but I can't modify the comment in the second object.
hope I have expressed myself correctly.
user_idin the post table