gpt4 book ai didi

php - 不应静态调用非静态方法 Illuminate\Support\Collection::where()

转载 作者:行者123 更新时间:2023-12-04 21:57:33 26 4
gpt4 key购买 nike

我尝试获取如下数据数组:

$coupons = $user->coupons::where('is_activated_flg', 1)->where('is_used_flg', 0)->lists('amount');

我有这个错误:

Non-static method Illuminate\Support\Collection::where() should not be called statically

你能告诉我问题是什么吗?

最佳答案

你可能想把它改成这样:

$couponQuery = $user->coupons()->where('is_activated_flg', 1)->where('is_used_flg', 0);
$couponCollection = $couponQuery->get();

..或合并:

$coupons = $user->coupons()->where('is_activated_flg', 1)->where('is_used_flg', 0)->get();

如果您使用的是 Laravel 5.1 或稍低版本,您可能需要考虑使用 pluck 而不是列表: https://laravel.com/docs/5.1/collections#method-pluck

$plucked = $collection->pluck('name');
$plucked->all();

关于php - 不应静态调用非静态方法 Illuminate\Support\Collection::where(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36916656/

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