Understand Input Trimming & Empty String Normalization

Punyapal Shah
Laravel automatically trims request strings and converts empty string inputs to null via default global middleware.

Laravel includes TrimStrings and ConvertEmptyStringsToNull middleware globally. Incoming string inputs are automatically trimmed of whitespace and empty strings ('') become null.

// Request input: ['name' => '  Punyapal  ', 'bio' => '']

$name = $request->input('name'); // Returns 'Punyapal'
$bio  = $request->input('bio');  // Returns null
  • TrimStrings removes leading and trailing whitespace automatically
  • ConvertEmptyStringsToNull normalizes empty form inputs ('') to null
  • Can be bypassed for specific fields (like passwords) via $except property
Tags: #Laravel #Middleware #Validation
Share on X

// Found an issue or want to contribute a tip? github.com/MrPunyapal/tips