[Vuejs]-How to validate data encoded with formData

0👍

The Request does not have a validate function.

One way to validate your request is:

<?php

...

use Validator;

class Controller extends BaseController
{
    ...
    public function update(Request $request){

        $array =  $request->all();
        $rules = array(
            'name' => 'required|string',
            'address' => 'required|strgin',
            'photo' => 'image'
        );

        $validator = Validator::make($array, $ules);
        if ($validator->fails()) {
            return $this->setStatusCode(400)->respond([
                'error' => [
                    'message' => $validator->messages(),
                    'status_code' => $this->getStatusCode()
                ]
            ]);
        }
        ...
        // store your data...
     }
}

Also check the available validation rules

Leave a comment