This issue will happen when users use query like the following:
$user = DB::table(‘users’)->find($user_id);
The find() method will assume the primary key configured in Laravel, which will be $id. In order to override this, you need to declare the MODEL (in this case, model USER) of which you will override the protected $primaryKey value to something else – for example ‘user_id’.
When used in the query builder (
What you should do instead is use
Or if you decide to use Eloquent Models you can specify the key column name:
And retrieve the model like this: