如何确定模型是否在Laravel 4.2中使用软删除?
在Laravel API中,我找到了函数isSoftDeleting(),但是显然它已从Laravel 4.2中删除,因为它使用了SoftDeletingTrait。
如何确定模型现在是否使用软删除?
如果要以编程方式检查模型是否使用软删除,则可以使用PHP函数class_uses
确定模型是否使用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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句