I have these models
class Device extends Model
{
use HasFactory;
protected $connection = 'traccar';
public function vehicle()
{
//Code I need
}
}
class Vehicle extends Model
{
use HasFactory;
protected $connection = 'mysql';
}
class VehicleDevice extends Model
{
use HasFactory;
protected $connection = 'mysql';
}
as you can see the Device is in a tracar database and the reset of the models are in the MySQL connection.
How do I write a hasOneThrough relationship for the devices to the vehicle?
I am getting an error that says
Table 'tracar.vehicles' doesn't exist (Connection: traccar, SQL: select * from `tc_devices` where exists (select * from `vehicles` inner join `vehicle_devices` on `vehicle_devices`.`id` = `vehicles`.`vehicle_device_id` where `tc_devices`.`id` = `vehicle_devices`.`device_id`))'