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

azbx's avatar
Level 17

Usernames Handler

So a user had signed up with the username index.php and going to their profile issues a laravel 404.

How may I prevent this?

0 likes
1 reply
thinkverse's avatar

Use proper validation rules, for example, the string rule as I understand it only checks with is_string, that will allow dots. What you want it to use is either alpha, alpha_num depending on if you want usernames to contain numbers, and alpha_dash for alpha-numeric characters, dashes, and underscores.

$input = [
    'username' => 'index.php',
];

$validator = Validator::make($input, [
    'username' => 'required|string',
]);

$validator->valid(); //  ["username" => "index.php"]

$validator = Validator::make($input, [
    'username' => 'required|alpha',
]);

$validator->valid(); //  []

Please or to participate in this conversation.