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

mtdesigners's avatar

Laravel-PHP 8.1 strict comparison fails on production

Hi there. My policy with strict comparison check fails on production, however if I use normal == comparison it passes as intended. any idea what to do? I appreciate all comments.

I check my PHP version and data type on both database tables. I really don't understand why it fails.

public function update(User $user, Post $post)
    {
        return $user->id === $post->user_id; // this fails
		return $user->id == $post->user_id; // this works
    }

EDIT: Both id and user_id return a type of integer, and the strict comparison works on local env.

Thank you all

0 likes
5 replies
mtdesigners's avatar

@jlrdw thanks, I'm not sure this is the right way to do it, but below note from that link gave me the idea:

Note: HTML Forms do not pass integers, floats, or booleans; they pass strings. To find out if a string is numeric, you may use is_numeric().

So I did it this way, even though I'm not sure if it's correct: 🤷‍♂️

public function update(User $user, Post $post)
    {
        return (int)$user->id === (int)$post->user_id;
    }
frankielee's avatar

@mtdesigners

Maybe you can use the method is in the trait ComparesRelatedModel

Example:

return $post->user()->is($user);
Niush's avatar
Niush
Best Answer
Level 50

May be you are using different database type (or very different versions) in local and production. SQLite for example could cause such issue.

Instead of manually type casting, using this in model might be easier:

protected $casts = [
    'user_id' => 'integer',
];
1 like
mtdesigners's avatar

@Niush Thank you for that type casting tip. I think the problem is using MariaDB which is on my production server and the old MySql server on my local env. I'm gonna have to look into that.

Thanks

Please or to participate in this conversation.