首页 \ 问答 \ Laravel雄辩的模型 - 模型扩展模型(Laravel eloquent model - model extends model)

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
更新时间:2022-03-02 22:03

最满意答案

现在没有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 ...
  • 你在混合使用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 ...
  • 尝试使用此前缀运行脚本。 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
  • 这个问题在这里解释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 ...
  • 适用于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 ...
  • 现在没有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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。