See https://www.php.net/manual/en/types.comparisons.php and note versions.
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
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',
];
Please or to participate in this conversation.