lundi 3 décembre 2018

Laravel: Validate parameters coming as a JSON string

Front End Part

The parameters are being sent like this:

Front End sending data

Laravel Request

class CarCreateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        //TODO: Define authorization logic, possibly a middleware
        return true;
    }  

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'car.name' => 'present|required'
        ];
    }
}

Real Problem

The request class always validates to false. I checked the Validating Array section, but it looks like this works sending parameters like this:

car[name]=Spidey Mobile

However, I need to send this data stringified using JSON.stringify().

Is there a workaround for this? Looks like dot notation isn't working since this is a JSON string rather than an array. I've tried modifying the request data before being actually evaluated but I haven't found anything that works for Laravel 5.7



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2BOELeQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire