试图在Laravel捕获ID时未定义的常数

发布于 01-23 19:08 字数 409 浏览 2 评论 0原文

我在Laravel中具有下面运行此代码的Laravel功能,

$data = AnggotaModel::where([
        ['status_nikah','Menikah'],
        ['jk','Pria']
    ])->get();

是从DD($ DATA)捕获的屏幕。

dd($ data);

我想要的是捕获ID结果

$id = $data[id];

是结果,它最终出现错误,

我该怎么办来修复此错误?

I have a function in Laravel which running this code below

$data = AnggotaModel::where([
        ['status_nikah','Menikah'],
        ['jk','Pria']
    ])->get();

below is the screenshoot captured from dd($data);

result of dd($data);

What I want is to catch the id so I use this code

$id = $data[id];

as the result, it ends up with an Error

What should I do to fix this error??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽2025-01-30 19:08:29

get()方法为您提供了项目的收集。获取首先元素,然后使用$ data [id]
在这里,您应该将其更改为:

$id = $data->first()[id];

// Or in a better way:

$id = $data->first()->id;

The get() method gives you a collection of items. Get the first element then use $data[id].
Here you should change it to:

$id = $data->first()[id];

// Or in a better way:

$id = $data->first()->id;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文