I using API resources with nested controllers, my urls look like:
GET /api/projects
POST /api/projects
...
GET /api/projects/:uuid/employees
POST /api/projects/:uuid/employees
I using also Request to save data per endpoint (for validation too).
The question is how to post data to save new employee (name, email, etc.) and validate and save value for project_id
from URL?
Request rules:
public function rules(): array
{
return [
'project_id' => ['required'],
'name' => ['required', 'max:30'],
'email' => ...,
];
}
My posted data has just name
and email
values and I would like get/set value for project_id
from URL, it is possible?
2
Answers
You can use
prepareForValidation
Yes, you can merge or add project_id to an existing request.