如何确定模型是否在Laravel 4.2中使用软删除 [英] How to determine if a model uses soft deletes in Laravel 4.2

查看:87
本文介绍了如何确定模型是否在Laravel 4.2中使用软删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定模型是否在Laravel 4.2中使用软删除?

How do I determine if a model uses soft deletes in Laravel 4.2?

Laravel API 中,我发现函数isSoftDeleting (),但很明显,由于它使用了SoftDeletingTrait,因此已从Laravel 4.2中删除.

In the Laravel API I found the function isSoftDeleting(), but apparently that was removed from Laravel 4.2 now that it uses the SoftDeletingTrait.

如何确定模型现在是否使用软删除?

How would I go about determining if a model uses soft deletes now?

推荐答案

如果要以编程方式检查模型是否使用软删除,则可以使用PHP函数class_uses确定模型是否使用SoftDeletingTrait

If you want to check programatically whether a Model uses soft deletes you can use the PHP function class_uses to determine if your model uses the SoftDeletingTrait

// You can use a string of the class name
$traits = class_uses('Model');
// Or you can pass an instance
$traits = class_uses($instanceOfModel);

if (in_array('SoftDeletingTrait', $traits))
{
    // Model uses soft deletes
}

// You could inline this a bit
if (in_array('SoftDeletingTrait', class_uses('Model')))
{
    // Model uses soft deletes
}

这篇关于如何确定模型是否在Laravel 4.2中使用软删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆