I have a dilemma that I try to do something that I do not know if it is even possible, I have 2 databases dpnmwin
and spi_intranet
of which dpnmwin
is an existing one of a long time ago and which I can not touch its structure for nothing, for which I had to create the other. In dpnmwin
there are many employee data which I bring without problem in a query between the 2 databases, the problem comes when I try to get the name of rol
that employees get in the system that I develop. spi_intranet
I had to create it because the other database did not have tables or fields for important information that I need like (roles, user, password), so create the other one.
With this query:
$user = Employee::join('spi_intranet.users', 'dpnmwin.nmtrabajador.CODIGO', 'spi_intranet.users.ci')
->where('dpnmwin.nmtrabajador.CODIGO', '=', $auth->ci)
->first();
It brings me all the data without problem but the rol
of the user brings me is the id
of rol
that they have in table roles
that is in spi_intranet
, with relations in laravel I can take the name
of the role but only of the user who is logged in at that moment, but of all the others only brings me the id
. Try to make a relation between the table nmtrabajador (dpnmwin)
and roles (spi_intranet)
asi
Model Employee
public function role(){
return $this->belongsTo('App\Role');
}
Model Role
public function employee(){
return $this->hasMany('App\Employee');
}
Which gives me the following error
SQLSTATE [42S02]: Base table or view not found: 1146 Table 'dpnmwin.roles' does not exist (SQL: select * from
roles
whereroles
.id
= 1 limit 1)
And I know that the error is because in the table nmtrabajador
there is no field roles
QUESTION: Is it possible to make this relationship between 2 tables of different tables? or is there any way to do this?