lukegalea16
4 months ago
254
16
Laravel

Laravel min Validation not working

Posted 4 months ago by lukegalea16

I am trying to validate a request as shown below and the max is working well, however if I enter a string of 2 characters for the device and data, it is still accepted and no error is returned.

if ($Request->has('data')) {
            $attributes = $Request->validate([
                'device' => 'required|string|min:6|max:8', //ID is minimum of 6, maximum of 8
                'seqNumber' => ['required','numeric'],
                'data' => ['required','min:22']
            ]);
            $device_data_message = new device_data_message();
            $device_data_message = $attributes;
            $device_data_message->bsId = '0';
            $device_data_message->nbRep = '0';
            $device_data_message->snr = '0';
            $device_data_message->rssi = '0';
            $saved = $device_data_message->save();
            if($saved){
                echo json_encode(array());
            }            
        }

Please sign in or create an account to participate in this conversation.