how to Validate json file using laravel 5.4?

Viewed 1967

I need to validate json file only when user upload from browser but doesn't works ,it works when i combined with txt file. working code source

 $this->validate($request, [
                // check validtion for json 
                'dataset_type' => 'required|mimes:json,txt'
            ]);

what i need is to validate json file only below code doesn't works

$this->validate($request, [
                // check validtion for json 
                'dataset_type' => 'required|mimes:json'
            ]);

even following codes don't works $this->validate($request, [

                'dataset_type' => 'required|file|mimes:application/json'
            ]);

Please anyone could she/he help me for this issue ? thanks.

1 Answers

Try, using mimetypes:application/json

'dataset_type' => 'required|file|mimetypes:application/json'
Related