gpt4 book ai didi

php - laravel 如何从多个表中获取列值?

转载 作者:行者123 更新时间:2023-11-29 15:37:44 24 4
gpt4 key购买 nike

如何代表第一个表的列特定 id 获取第二个表的列值,就像在这段代码中,它从同一个表获取值,但我想更改它以代表从其他表获取值用户表的列 ID。

    $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();

最佳答案

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();

关于php - laravel 如何从多个表中获取列值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58061779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com