gpt4 book ai didi

mysql - 如何使用 Laravel 从存储在数组中的单列获取数据?

转载 作者:行者123 更新时间:2023-11-29 15:18:07 26 4
gpt4 key购买 nike

我需要从字段 array_payout 中单独获取每一列,任何人都可以解决它

$currentMonth_start_Date = Carbon::now()->startOfMonth()->subMonth(1);
$currentMonth_end_date = Carbon::now()->subMonth()->endOfMonth();

$clients_referral_tree = DB::table('mam_referral_payout')
->select('clients.id', 'mam_referral_payout.*')
//->addSelect(DB::raw('SUM(mam_referral_payout.Final_amount) as referral_amount'))
->leftjoin('clients', 'clients.id', '=', 'mam_referral_payout.to_id')
->where('clients.id', '=', (Auth::user()->id))
->whereBetween('mam_referral_payout.created_at', [$currentMonth_start_Date, $currentMonth_end_date])->get();

$clientTree = [];

foreach ($clients_referral_tree as $tree) {
$clientThree = $tree;
$clientTree[] = $clientThree;
}

dd($clientTree);

Image Description

最佳答案

您可以将以下内容添加到您的模型中:

protected $casts = [
"array_payout" => "object"
];

为 json 中的每个属性添加一个访问器,如下所示:

public function getTotalAmountAttribute(){
return optional($this->array_payout)->total_amount;
}

您可以像这样使用它们:

$clientTree1->total_amount;

关于mysql - 如何使用 Laravel 从存储在数组中的单列获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59541148/

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