0

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']
        ];
    }
}
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Sonia Behal
  • 63
  • 1
  • 1
  • 5

2 Answers2

2

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());
2

Set postman Header properly:

Content-Type: application/json

Accept: application/json