首页 > 解决方案 > 为什么 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 命令后发生的。

我清除了缓存,但它不起作用。

标签: laraveleloquent

解决方案


谢谢大家,我发现我的错误:

我为表的 deleted_at 列设置了时间戳,但忘记设置不为空,所以当我添加数据时它也填充了 deleted_at 列。这就是为什么雄辩的子句返回空的原因。
如此愚蠢的错误!


推荐阅读