简体   繁体   English

如何在Laravel中编辑软删除的数据而不将其还原?

[英]How to edit soft deleted data without restore it in Laravel?

I have used SoftDelete to delete an event from events table. 我已使用SoftDeleteevents表中删除events SoftDelete is working fine. SoftDelete运行正常。 I have shown that SoftDelete event withTrashed() in view and it showing. 我已经在视图中显示了SoftDelete事件withTrashed()并显示了它。 Now i want to edit that SoftDelete event data without restore it. 现在,我想编辑该SoftDelete事件数据而不恢复它。 Is it possible? 可能吗?

I am getting an error 400 - we could not find the page when i have tried it. 我收到错误400-尝试过该页面后找不到

$data['events'] = $qBuilder->EventComplete()->withTrashed()
                    ->orderBy('events.event_date', 'desc')
                    ->groupBy('events.id')
                    ->paginate(AppHelper::getConfigValue('ADMIN-PAGINATION-LIMIT'));

It should be possible like this: 应该是这样的:

Model::withTrashed()->find(5)->update(['attribute' => 'value']);

so you are using eloquent apply withTrashed - find single model (here with id = 5) and then you update attributes you want. 因此,您正在雄辩地使用withTrashed-查找单个模型(此处ID = 5),然后更新所需的属性。

You haven't showed more but, but in your case assuming you use Route model binding you might need to adjust it to allow to find also soft deleted models: 您没有显示更多,但是,在您情况下,如果您使用Route模型绑定 ,则可能需要对其进行调整以允许找到软删除的模型:

Route::bind('user', function ($value) {
    return App\User::withTrashed()->findOrFail($value);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM