Reputation: 73
For the following request, when body params are sent as JSON, it always validates the request (as in no validation rule is triggered), but when sent in form-data or form-urlencoded, it passes through validation rules. Is it a limitation with Laravel?
namespace App\Api\Requests\OrganizationUser;
use App\Api\Constants\PlatformRoles;
use Framework\Http\Requests\APIFormRequest;
class CreateNewUserRequest extends APIFormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'bail|required|string|max:255',
'access' => 'present|array',
'access.*.access_type' => ['bail', 'sometimes', 'string'],
'access.*.id' => ['bail', 'sometimes', 'string']
];
}
}
Upvotes: 0
Views: 1384
Reputation: 31
Set postman Header properly:
Content-Type: application/json
Accept: application/json
Upvotes: 3
Reputation: 41
couz when you send it as form-data the body structure were changed try to dd your request and see how the request look like.
public function rules()
{
dd($this->request->all());
Upvotes: 2