-
Notifications
You must be signed in to change notification settings - Fork 605
Closed
Labels
Description
My form request controller is a bit non-standard - it changes the optional-ness of the fields for a patch request, in an attempt to avoid having to repeat the rules for each type. Fair enough right - 'DRY' code?
The trouble is, then I get nothing in my docs. GET returns no rules (why should it?) so the doc contains no rules.
I can hack this by returning the rules on GET irrelevantly, but it doesn't solve the difference between PUT, POST, and PATCH where every field is optional.
Here's my FormRequest rules for example:
$requiredRules = [
'state_id' => 'required|integer',
'name' => 'required|min:3|max:191',
'status' => 'required|string', // ['required', new ProjectStatus],
'phase' => 'required|string', // ['required', new ProjectPhase],
'owner_id' => 'required|integer',
'value' => 'nullable',
'contact_id' => 'nullable',
'customer_id' => 'nullable',
];
switch($this->method())
{
case 'PUT':
case 'POST':
return $requiredRules;
case 'PATCH':
return $this->getPatchRules($requiredRules);
case 'GET':
case 'DELETE':
return [];
}I'm going to see if I can figure out how to fix this, but any help would be appreciated.