覆盖模型的软删除表列(Overwriting soft delete table column for a model)
我正在使用laravel 5.4。
我有一个指向具有以下属性的数据库表的模型。
id integer name varchar location varchar deleted boolean
这是一张旧表,由于它与一堆代码交织在一起,我们无法更改此表。
我想要做的是利用模型中的laravels软删除功能。 我知道laravel期望列名为
deleted_at
,数据类型为数据库表上的date
。我如何覆盖这个,以便Laravel查看
deleted
的列并检查它是否是一个boolean
?我已经尝试查看我的模型继承的类,但是无法找到定义处理它的常量和函数的位置。 我怀疑它可能在收藏品上,但没有运气。
理想情况下,我想简单地重新定义我的模型中的函数。
谢谢。
I'm using laravel 5.4.
I have a model that points to a database table that has the following attributes.
id integer name varchar location varchar deleted boolean
This is an old table and due to it being entwined in a bunch of code we can't change this table.
What I want to do is take advantage of laravels soft delete functionality within a model. I know that laravel expects the column name to be
deleted_at
and the data type to bedate
on the database table.How do I override this so this so that Laravel will look at the column
deleted
and check if it's aboolean
?I've tried looking at the classes that my model inherits from but haven't been able to find where the constant and function that handles this is defined. I suspect it might be on the collection but have had no luck.
Ideally I would like to simply redefine the functions in my model.
Thanks.
原文:https://stackoverflow.com/questions/47721342
最满意答案
出于调试和测试目的,但以安全为代价。
For the debugging and testing purposes but at the cost of security.
相关问答
更多-
为什么我们需要容器?(Why do we need containers?)[2022-11-08]
在我看来,容器的价值(如容器理论)就是它们的一致性 。 这种一致性使得使用容器表示作为可执行规范的基础,甚至可能使用机器辅助的程序派生。 容器:理论工具,而不是一个很好的运行时数据表示策略 我不会推荐(标准化)容器的固定点作为实现递归数据结构的一种很好的通用方法。 也就是说,知道给定的函子具有(最多为iso)作为容器的演示文件是有帮助的,因为它告诉您可以实例化通用容器功能(这很容易实现,一次完成,归功于均匀性)可以实例化到你特定的仿函数,以及你应该期望的行为。 但这并不是说容器实现将以任何实际的方式高效。 ... -
从STL容器继承实现而不是委托吗?(Is it okay to inherit implementation from STL containers, rather than delegate?)[2022-03-06]
风险是通过指向基类 ( delete , delete []和潜在的其他释放方法的指针来解除分配)。 由于这些类( deque , map , string等)没有虚拟的dtors,所以不可能只使用指向这些类的指针来正确清理它们: struct BadExample : vector{}; int main() { vector * p = new BadExample(); delete p; // this is Undefined Behavior return 0; ... -
我采取“何时适当”的方法。 我们的想法是,您希望使用最有意义的名称来命名您的类。 在某些情况下,它确实意味着类名称在某种程度上与命名空间有些冗余,但请记住,除了作为using指令的一部分之外,命名空间通常不会被视为代码中类名的一部分。 命名空间用于逻辑地将相关类等组合在一起,以帮助开发人员找到正确的类并帮助最小化名称冲突的可能性。 I take the "when it is appropriate" approach. The idea is that you want to name your clas ...
-
发生这种情况是因为完全限定名称不同 - 一个是Foo.IOptions ,另一个是Bar.IOptions 。 请注意,声明合并仅在具有相同的完全限定名称时才会发生: namespace Foo { export interface IOptions { a?: number; } } namespace Foo { export interface IOptions { b?: string; } } var options: Foo.I ...
-
是否存在在容器中合并命名空间可能有用的用例(Are there any use cases where merging the namespace in containers can be useful)[2022-12-25]
出于调试和测试目的,但以安全为代价。 For the debugging and testing purposes but at the cost of security. -
kubelet不会为/ var / log / containers创建符号链接(kubelet does not create symlinks to /var/log/containers)[2022-07-28]
最后我发现了造成这个问题的原因。 从CentOS 7 repo安装docker时,有一个选项(--log-driver = journald)强制docker将日志输出运行到journald。 默认行为是将这些日志写入json.log文件。所以,我唯一要做的就是从/ etc / sysconfig / docker中删除最后提到的选项。 Finally i found out what was causing the issue. when installing docker from CentOS 7 r ... -
这篇博客有关于使用自定义命名空间的精彩帖子,并给出了一些示例。 This blog has a great post about using custom namespaces and gives you a few examples as well.
-
如果你的容器持有指针,那么这些对象的析构函数将不会被调用(STL不会跟随这些指针并调用指针的析构函数)。 相反,如果你的容器本身持有全尺寸的对象,那么将调用这些对象的析构函数。 您在map声明和insert语句中也有一些语法错误。 尝试运行以下代码。 注意,析构函数只被调用一次 (用于delete语句)。 从不为析构语句调用析构函数 。 #include
-
.namespace.mixin是指具有两个类的元素,而.namespace .mixin会在.namespace中找到所有.mixins,或者只是一个错字? Update: I've found similar topic (even with more comprehensive list of examples/tests) in the official less.js issues list: https://github.com/less/less.js/issues/1205. This se ...
-
为什么不尝试add cases而不是add variables ? 如果没有相同ID的相同日期出现,它应该与casestovars一起正常工作。 如果出现这种情况,您需要先考虑要对它们做什么,然后才能继续使用casestovars 。 一种方法是按ID和DATE进行聚合,并决定是否要为此案例添加数据变量。 Why not try add cases instead of add variables? if there are no occurrences of the same Id with the sa ...