Как получить значения столбцов из нескольких таблиц в laravel? - PullRequest
0 голосов
/ 23 сентября 2019

Как я могу получить значение столбца второй таблицы от имени идентификатора столбца 1-й таблицы, как в этом коде он получает значения из той же таблицы, но я хочу изменить его, чтобы получить значения из другой таблицы от имениидентификатора столбца таблицы пользователя.

    $user = User::find(Auth::id());
    $ref_id = $user->referrer_id;
    $ref_user = User::find($ref_id);
    $new_Balance = $ref_user['balance']  = $ref_user['balance'] + 
    $comission->update_commision_sponsor;
    $ref_user->save();

Я хочу, чтобы это было так:

    $user = User::find(Auth::id());
    $ref_id = $user->referrer_id;
    $ref_user = User::find($ref_id); (here I want to assign second table where the referrer_id column dose not exist.)
    $new_Balance = $ref_user['balance (here I want second table's column "earning")']  = $ref_user['balance(here I want second table's column "earning")'] + $comission->update_commision_sponsor;
    $ref_user->save();

1 Ответ

0 голосов
/ 23 сентября 2019

Условие if может помочь

$user = User::find(Auth::id());
$ref_id = $user->referrer_id;

if($ref_id == null){
    $anotherTable = AnohterTable::find($id);
    $ref_id == $anotherTable->another_column;
}

$ref_user = User::find($ref_id); (here I want to assign second table where the referrer_id column dose not exist.)
$new_Balance = $ref_user['balance (here I want second table's column "earning")']  = $ref_user['balance(here I want second table's column "earning")'] + $comission->update_commision_sponsor;
$ref_user->save();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...