laravel - 如何从 eloquent 选择变量
问题描述
我有这个从表 petugas 中选择 id 的代码,并且有声明 where from auth
$petugas = petugas::where('ID_PETUGAS','=',auth()->user()->id);
我想把那个id放到这段代码中
Peminjaman::create([
'ID_ANGGOTA' => $request->ID_ANGGOTA,
'ID_BUKU' => $request->ID_BUKU,
'ID_PETUGAS' => $petugas->ID_PETUGAS, --> to this
'TANGGAL_PINJAM' => $request->TANGGAL_PINJAM,
'TANGGAL_KEMBALI' => $request->TANGGAL_KEMBALI
]);
如何获取这些变量的输入?
解决方案
使用 first() 方法:
$petugas = petugas::where('ID_PETUGAS','=',auth()->user()->id)->first();
然后
echo $petugas->ID_PETUGAS;
推荐阅读
- javascript - 防止悬停卡超出页面
- python - Python 嵌套 JSON 导入 - 转换为表格
- jetbrains-ide - 如何在 JetBrains YouTrack 上的自定义多字段上发送电子邮件?
- ajax - 使用 Ajax 调用调用 MVC 控制器方法不起作用
- android-multidex - 由于 Mutlidex 错误,Flutter 构建失败
- fonts - PhpStorm:编辑器中部分不同的字体
- java - 在 kotlin 类中调用 Java 单例类时出现 NoClassDefFound 错误
- javascript - 如何使用 exporter 导出所有字段?(反应管理员)
- php - 在 WooCommerce 中显示免费送货和送货信息前还剩多少
- android - 创建 ViewHolder 工厂