'Making relation between two tables of two different databases

I am trying to create a many to many relation between two table two different databases one table is in daily named database, table icboms another table is in daily 2 database and table name is item_availabilities, connection between two table is icboms.master_item = item_availabilities.item_id

the ids are in string format only example E2LK35ICAD when i create a relation between them it showing me this error

"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'daily2.item_id' doesn't exist (SQL: select item_availabilities.*, item_id.master_item as pivot_master_item, item_id.order_elco_item_availability_id as pivot_order_elco_item_availability_id from item_availabilities inner join item_id on item_availabilities.id = item_id.order_elco_item_availability_id where item_id.master_item in (130, 1246, 1252, 1255, 1455, 3005, 3551))"

What I have tried in Icbom model:

use Filterable;

protected $connection = 'mysql';
protected $table = 'icboms';
public function item_availability(){
        return $this->belongsToMany('App\Models\ordersElco\OrderElcoItemAvailability','item_id','master_item');
}

in OrderElcoItemAvailability model :

protected $connection = 'mysql2';
    protected $table = "item_availabilities";

    public function icbom_master(){
        return $this->belongsToMany('App\Models\Icbom','master_item','item_id');
    }

in controller :

$or = Icbom::with('item_availability')->where('component_item',$itemId)->get();
return $or;

please help me solve this issue consuming a lot of time than it should thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source