What's your tables structure?
Jun 1, 2022
13
Level 3
Eloquent uses wrong foreign key with belongsTo even after dump-autoload
I was getting an error:
(PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'phones.users_id'
Then I realized that the Users model name is in plural, so I edited the relationship:
public function user()
{
return $this->belongsTo(Users::class,'user_id');
}
and ran composer dump-autoload and even php artisan cache:clear but I still get the same error.
Why is it not working?
*Edit: Looks like the Observer code is not updating from some reason
Please or to participate in this conversation.