【发布时间】:2021-12-02 20:04:27
【问题描述】:
我想在 UserEnabledNotifications 的 NotificationTypesId 列上将表 NotificationTypes 与 UserEnabledNotificationTypesId 联接,仅适用于 NotificationTypes 表的 deleted_at 列为空的行。我试过如下。但它不是对NotifocationTypes 表中deleted_at 列的null 值进行排序。有什么解决办法吗?
UserEnabledNotifications::with('userNotications', function ($query){
$query->whereNull('deleted_at');
})->select('userId','notificationTypesId')->get();
UserEnabledNotifications
public function userNotifications(){
return $this->belongsTo(NotificationTypes::class, 'notificationTypesId','id');
}
【问题讨论】:
-
不需要写
whereNull条件。对于deleted_atlaravel,它会自行将deleted_at是一个空条件附加到查询中。因此,请尝试不使用它。 -
@Vivek Pawar 在有或没有空条件的情况下都没有排序
-
你想要
orderby的关系吗? -
@Vivek Pawar 我只是想以任何方式实现我在原始问题中所说的话
标签: php laravel eloquent laravel-8 query-builder