K
K
kupurim2018-07-27 15:45:59
Laravel
kupurim, 2018-07-27 15:45:59

How to make user authorization if the data is stored in different tables?

Hello.
There is a User table, it contains a name, mail, password, almost everything you need. But there is also a User_info table in which the phone is stored. It is necessary to make authorization by phone and password.
How can I do that?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-07-27
@kupurim

By phone, we look for the user id in the User_info table, and then we check the correctness of the password from the User table.

$userInfo = UserInfo::where('phone', $request->get('phone', ''))->firstOrFail();
$user = User::findOrFail($userInfo->user_id);
if(\Hash::check($request->get('password', ''), $user->password))
{
    auth()->login($user, true);
}

J
JhaoDa, 2018-07-28
@JhaoDa

Not a crutch solution -  https://laravel.com/docs/5.6/authentication#adding...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question