Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

baskarks's avatar

mimes:ttf does not working in validation

mimes:ttf,otf,woff,woff2 not validating

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like you're trying to validate font files in a Laravel application and encountering issues with the mimes validation rule. The mimes rule should be followed by the MIME types, not the file extensions. For TrueType fonts, the MIME type is font/ttf or application/x-font-ttf. For OpenType fonts, it's font/otf or application/x-font-otf. For WOFF files, it's application/font-woff, and for WOFF2, it's font/woff2.

Here's how you can adjust your validation rule:

$request->validate([
    'font' => 'mimes:application/x-font-ttf,application/x-font-otf,application/font-woff,font/woff2'
]);

Or, if you want to use the file extensions, you can use the mimetypes validation rule instead:

$request->validate([
    'font' => 'mimetypes:font/ttf,font/otf,application/font-woff,font/woff2'
]);

Remember that the validation will depend on the server being able to correctly identify the MIME type of the file being uploaded. If the server is not recognizing the MIME type correctly, you might need to add the MIME types to your server's configuration or use a custom validation rule to check the file extension directly.

If you want to validate by file extension, you can create a custom rule or use regex:

$request->validate([
    'font' => 'regex:/\.(ttf|otf|woff|woff2)$/i'
]);

This regex rule will check the file extension regardless of the MIME type. However, be aware that validating by file extension is less secure than validating by MIME type, as it's easier to spoof a file extension than a MIME type.

Please or to participate in this conversation.