B
B
Berkutman2020-07-17 20:48:27
Laravel
Berkutman, 2020-07-17 20:48:27

How to define a relationship with a table from another database in laravel 7?

After reading the documentation about the definitions of relations between tables, I did not find information on how to implement a relationship to the example of the User module (which is out of the box make:auth ) with any table from another database
. I need to display information about an authenticated user from a table located in another database. Auth::user()->name ( standard solution for getting
username from database )
Auth::user()->nameothertable - something like that

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-07-17
@Berkutman

since another database, then you need to define another connection to the database and for the model, whose table in another database, set the connection parameter, and then everything is the same as with other models. https://laravel.com/docs/7.x/eloquent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question