我正在尝试获取单个列的最后一个用户记录,以将其添加到其他表中的另一列中
我尝试过这样编码
{
$data = request()->validate([
'accnumber' => 'required',
'amt_debit' => 'required',
'bankname' => 'required',
'swift_code' => 'required',
'Remarks' => 'required',
'acc_type' => 'required',
]);
// auth()->user()->funds()->create($data);
$user_id = auth()->user()->id;
$debit = DB::table('funds')->where('user_id', $user_id)->pluck('amt_debit')->latest()
->first();
$amt = DB::table('accounts.balance')->where('user_id', $user_id)->first();
$sum = $debit + $amt;
echo $sum;
}
请我对此有所了解
答案 0 :(得分:0)
尝试像这样更改总和代码:
$sum = $debit->amt_debit + $amt->balance;
因为选择一列,它会像这样返回:
attributes: array:1 [
"amt_debit" => "your amount"
]
因此您需要从班级中调用该列。
答案 1 :(得分:0)
如果您只需要单个值,一行中的单个列,则可以使用from math import sqrt
keyboard_cartesian = {'q': {'x':0, 'y':0}, 'w': {'x':1, 'y':0}, 'e': {'x':2, 'y':0}, 'r': {'x':3, 'y':0}, 't': {'x':4, 'y':0}, 'y': {'x':5, 'y':0}, 'u': {'x':6, 'y':0}, 'i': {'x':7, 'y':0}, 'o': {'x':8, 'y':0}, 'p': {'x':9, 'y':0}, 'a': {'x':0, 'y':1},'z': {'x':0, 'y':2},'s': {'x':1, 'y':1},'x': {'x':1, 'y':2},'d': {'x':2, 'y':1},'c': {'x':2, 'y':2}, 'f': {'x':3, 'y':1}, 'b': {'x':4, 'y':2}, 'm': {'x':5, 'y':2}, 'j': {'x':6, 'y':1}, 'g': {'x':4, 'y':1}, 'h': {'x':5, 'y':1}, 'j': {'x':6, 'y':1}, 'k': {'x':7, 'y':1}, 'l': {'x':8, 'y':1}, 'v': {'x':3, 'y':2}, 'n': {'x':5, 'y':2}, }
def euclidean_distance(a,b):
X = (keyboard_cartesian[a]['x'] - keyboard_cartesian[b]['x'])**2
Y = (keyboard_cartesian[a]['y'] - keyboard_cartesian[b]['y'])**2
return math.sqrt(X+Y)
for i in keyboard_cartesian.keys():
for j in keyboard_cartesian.keys():
distance_from_i_to_j = [(i, j, euclidean_distance(i, j))]
方法:
value
Laravel 6.x Docs - Query Builder - Retrieving Results - Retrieving A Single Row / Column From A Table $debit = DB::table('funds')
->where('user_id', $user_id)
->latest()
->value('amt_debit');
$amt = DB::table('accounts')
->where('user_id', $user_id)
->value('balance');