Laravel eloquent relations not working

On the above example, I need to provide an order number, Product ID and Product Name. Thus, I need to provide a function in Laravel Eloquent Relations Not Working

Your Error Display AS:

Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘users.users_item_id’ in ‘field list’ (SQL: select user.*, users.users_item_id as laravel_through_key from products inner join orders on orders.id = users.user_id where users.users_item_id = 68 limit 1)

User Model:

public function users() {
    return $this->belongsTo('Model_NAME','FIRST_TBL_ID','SECOND_TABLE_ID');
}

Item Model:

Solution 1:

And hasMany for the user_items relationship of User Model

IF NOT WORKING FOLLOWING THIS COMMAND AND HIT YOUR PROJECT:

Cleared following;
cache:clear
config:clear
route:clear
composer update
composer dumpautoload
Browser Cache Cleared
Still not working
Help Appreciated

1 thought on “Laravel eloquent relations not working”

Leave a Comment