Laravel雄辩的模型 - 模型扩展模型(Laravel eloquent model - model extends model)
是否有可能用另一个模型扩展laravel 4 eloquent模型,假设我有一个用户模型扩展了雄辩的类,另外还有第二个类,一个扩展用户类的管理员类?
如果我只是将管理员类链接到用户,则必须首先获取用户的管理员属性然后获取管理员属性来访问管理员属性。
编辑:
假设我让管理员没有扩展用户。 我必须访问例如电话号码(管理员属性),例如
$user = User::find(1); $phone = $user->administrator->phone;
$user = User::find(1); $phone = $user->administrator->phone;
但是通过让管理员扩展用户,我可以直接访问电话号码,例如$user = Administrator::find(1);
(请注意,找到管理员的ID与我用来获取用户的ID相同。通常我必须在管理员数据库中传递条目的真实ID)$phone = $user->phone;
同时,可以访问用户类的属性,例如$phone = $user->email;
或者可能有一个更好的解决方案来实现这一点,或者像这样使用它是没有意义的,如果是这样,请随时告诉我
is it possible to extend a laravel 4 eloquent model with another model, let's say i have a user model extending the eloquent class and additionally there is a second class, a administrator class extending the user class?
If i just linked the administrator class to the user i'd have to access the administrators attributes by first getting the administrator attribute of the user and then getting the admins attributes.
EDIT:
Let's say I have the Administrator not extending the User. I'd have to access e.g. the phone number(a administrators attribute) like this
$user = User::find(1); $phone = $user->administrator->phone;
but by letting the Administrator extend the User I am able to access the phone number directly like this maybe$user = Administrator::find(1);
(Note that the id passed to find the Administrator is the same like the one I use to get the user. Normally I would have to pass the real id of the entry in the Administrator database)$phone = $user->phone;
At the same time it would be possible to access an attribute of the user class e.g.$phone = $user->email;
or maybe there is a better solution to achieve this or it makes no sense to use it like this, if so, feel free to tell me
原文:https://stackoverflow.com/questions/16565486
最满意答案
现在没有QString,Qt直接使用unicode代替它:
_fromUtf8 = lambda s: s
There is no QString now, Qt use unicode directly instead so replace it:
_fromUtf8 = lambda s: s
相关问答
更多-
我刚刚通过apt-get测试了sip / pyqt的安装并安装了它: 啜饮4.12.4 PyQt4 4.8.5 您报告的sip版本是开发快照。 我建议删除它,做一个sudo apt-get update ,然后再sudo apt-get install python-sip python-qt4 。 否则,你可以从源代码中执行最新的稳定版本: 啜饮4.14.2 PyQt4 4.9.6 如果您有混合安装,请尝试并删除所有这些。 随着点你可以做pip remove sip 。 或者你可以进入一个python s ...
-
PyQt4和pyuic4(PyQt4 and pyuic4)[2022-08-08]
你在混合使用Python和shell命令。 这是Python代码,可以在交互式Python会话中执行: import sys sys.path.append('/Users/womble/Dropbox/scratch/') from PyQt4 import QtCore, QtGui 这应该是从命令提示符或终端窗口运行。 它在Python解释器中给出语法错误,因为它不是Python: pyuic4 Urb.ui > Urb.py You're mixing Python and shell comm ... -
PyQt4 OSX错误的架构(PyQt4 OSX Wrong architecture)[2023-09-23]
尝试使用此前缀运行脚本。 VERSIONER_PYTHON_PREFER_32_BIT=no /usr/bin/python exampleosx.py Try running your script with this prefix. VERSIONER_PYTHON_PREFER_32_BIT=no /usr/bin/python exampleosx.py -
AttributeError:'模块'对象没有属性'QtString'(AttributeError: 'module' object has no attribute 'QtString')[2023-06-14]
这个问题在这里解释http://inputvalidation.blogspot.com/2010/10/python3-pyqt4-and-missing-qstring.html 你无法加载QString的原因是它从PyQt4中丢失(可能更早,谁知道)。 由于Py3k与Py2k相比,默认情况下支持Unicode,所以在这个类中不需要。 为了兼容性的原因,您应该在import的某个地方使用以下代码片段来代替QString: try: from PyQt4.QtCore import QString ... -
我通过删除Python并使用macPorts安装python和pyqt解决了这个问题。 I Solved this problem with delete Python and installing python and pyqt with macPorts.
-
也许检查你是否正确安装了PyQt4? 为此,您可以简单地使用: import PyQt4 并查看它是否产生错误。 I resolved the issue! there was a duplicated PyQt4 in my python folder than I tried to installed before and failed . when I removed that duplicate folder and uninstalled my older python version it w ...
-
PyQt4和64位python(PyQt4 and 64-bit python)[2023-06-12]
适用于Windows的64位PyQt二进制文件可在http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt上找到。 更新:适用于Windows的64位PyQt4二进制文件,包括MySQL扩展,现在可从Riverbank正式获取, 网址为http://www.riverbankcomputing.co.uk/software/pyqt/download 64 bit PyQt binaries for Windows are available at http://www ... -
如何删除QtString中的错误。(How do i remove the error in QtString. Am using pyqt4 and Python 3.4.3)[2023-05-15]
现在没有QString,Qt直接使用unicode代替它: _fromUtf8 = lambda s: s There is no QString now, Qt use unicode directly instead so replace it: _fromUtf8 = lambda s: s -
经过大量的血,汗和泪,我已经整理了一个完整的使用python 3在小牛上安装pyqt的完整列表: brew install python3 brew install qt brew install sip --with-python3 brew install pyqt --with-python3 将其添加到.bash_profile: PYTHONPATH=/usr/local/lib/python3.3/site-packages:$PYTHONPATH 重启你的电脑。 After a lot o ...
-
我怀疑当你运行脚本而不是二进制文件时也会发生同样的错误,因此问题与PyInstaller无关。 因为看起来像self.ui.actionExport_Database等是QAction实例,它确实没有activated属性。 你可能意味着triggered : 当用户激活动作时发出该信号; 例如,当用户单击菜单选项,工具栏按钮或按下操作的快捷键组合时,或者调用trigger()时。 I suspect that the same error also occurs when you run the scri ...