@php function stringToColorCode($str) { $code = dechex(crc32($str)); $code = substr($code, 0, 6); return '#ff0000'; } function getContrastYIQ($hexcolor) { $r = hexdec(substr($hexcolor, 1, 2)); $g = hexdec(substr($hexcolor, 3, 2)); $b = hexdec(substr($hexcolor, 5, 2)); $yiq = ($r * 299 + $g * 587 + $b * 114) / 1000; return $yiq >= 128 ? 'black' : 'white'; } $initials = strtoupper(substr(Auth::user()->name, 0, 1)) . strtoupper(substr(strstr(Auth::user()->name, ' '), 1, 1)); $bgColor = stringToColorCode(Auth::user()->name); $textColor = getContrastYIQ($bgColor); @endphp