laravel - 为什么 Laravel eloquent 返回空
问题描述
这是我的模型
namespace App\Models\Invitation;
use App\Models\Model;
class SendtoType extends Model
{
}
当我从 SendtoType 获取数据时,它返回空或 null 但我确定 sendto_types 表有数据
$types = SendtoType::all();
dd($types); // return empty collection
$types = SendtoType::find(1);
dd($types);// null
这是在我运行 php artisan command:reset_table sendto_types 命令后发生的。
我清除了缓存,但它不起作用。
解决方案
谢谢大家,我发现我的错误:
我为表的 deleted_at 列设置了时间戳,但忘记设置不为空,所以当我添加数据时它也填充了 deleted_at 列。这就是为什么雄辩的子句返回空的原因。
如此愚蠢的错误!
推荐阅读
- python - 离线打开 Plotly Express Graphs
- ios - 如何在 Mac 上的 iOS 模拟器上运行 .ipa 文件?
- javascript - 根据天数重新计算值并将其显示在文本字段中
- java - 贝尔曼福特实施和同时放松
- python-3.x - ValueError:形状 (32, 5, 5) 和 (32, 2) 不兼容
- python - 调用方法与 setattr
- javascript - JavaScript 在点击时显示不可见的 div
- scala - 函数式 Scala 编程模式匹配
- node.js - 向客户端服务器添加了 SSL,但仍未与后端服务器 nodejs 执行握手
- javascript - 缩放后如何重置 HTML5 画布?