1

This is very strange. I have an endpoint that accepts a PUT request.

namespace App\Http\Requests;
use Dingo\Api\Http\FormRequest;
class UpdateTestRequest extends FormRequest
{
    
    public function authorize()
    {
        return true // guaranteed to work
    }

    public function rules()
    {
        return [
          'is_invited' => 'required|boolean',
          'is_span_invited' => 'required|boolean',
        ];
    }
}

When I make the request in insomnia, it works fine when accepting a JSON payload.enter image description here

However, changing to type Multipart form data and PUT'ing again - the UpdateTestRequest is run again but it fails. Laravel doesn't seem to see the values in is_invited nor is_span_invited. Doesn't matter is the expected value is a string, int etc.

Very strange.

enter image description here

Simon
  • 2,484
  • 6
  • 35
  • 54
  • Looks like it's related to this: https://stackoverflow.com/questions/50691938/patch-and-put-request-does-not-working-with-form-data – Simon May 07 '22 at 06:44

2 Answers2

0

I think true is being parsed as string by laravel backend. Did you try sending 0 and 1 instead?

0

Use _method="PUT" in request body and POST. https://laravel.com/docs/9.x/routing#form-method-spoofing

Simon
  • 2,484
  • 6
  • 35
  • 54