drkj41932 2016-07-14 16:52
浏览 18
已采纳

Laravel与其他表的几列关系

I have a question about relationship tables in Laravel. I have a table "revisions" wherein I have columns "old_value" and "new_value". This table stores the change history records. The problem is when i want return records with table "revision" on page. The return value is, example:

"User Jack change name products from 1 to 2"

but I want to be the return value:

"User Jack change name products from BALL to SHOES"

Is there a way to combine the relationship table "revision" of the table "products", "articles" and "categories". For example based on the value of the columns "revisionable_type" or "key". The problem is that to columns "old_value" and "new_value" saved is records from columns "article_id", "category_id" with table "products" and colums "id" with table "articles" and colums "id" with table "categories"

Screen table: "revision":http://iv.pl/images/78755893242784790812.png

Screen table: "products":http://iv.pl/images/82849082096359450147.png

Screen table: "articles":http://iv.pl/images/81440394780221859215.png

Screen table: "categories":http://iv.pl/images/03724618899545660879.png

  • 写回答

1条回答 默认 最新

  • duangai1916 2016-07-14 17:38
    关注

    An easy way out would be to query each id on the category table.

    <div>User {{ $user }} change name products from 
    {{ Category::whereId(*theId*)->first()->category_name }}
    to
    {{ Category::whereId(*theId*)->first()->category_name }}
    </div>
    

    Although, I think the real problem lies within your table structure. The old_value and new_value on Revisions table are relations to the category table. Try to find out more about how to normalize your tables.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用