如何在 Laravel 中从外键中查看表字段
问题描述
我是 Laravel 的新手,语法不好.我想通过外键(该表的id)查看另一个表的值.
I'm new at Laravel and not good with syntax. I want to see the values of another table through the foreign key(id of that table).
https://ibb.co/pXRFRHn 您可以在这张图片中看到我在用户 & 下获得了 id;班级.我想要与这些 ID 关联的标题.
https://ibb.co/pXRFRHn You can see in this picture I get ids under user & class. I want the titles associated with these ids.
我有表格部分、用户和课程.我使用 class_id &user_id 作为节表中的外键.当我尝试显示数据时,我看到了 id,但我想要名称 &从该 id 中提取的其他字段.
I have tables sections,users and a class. I use class_id & user_id as the foreign key in the section table. When I try to show data, I see the id, but I want the name & other fields extracted from that id.
控制器
刀片/视图
具体...
由此,我得到了类 id,但我也想要它的名字.
From this, I get the class id, but I want its name also.
但是,它不起作用.
我已经编辑了模型
截面模型
推荐答案
你要做的就是
不如试试这个
我假设您的表名是类,因为您想显示类名,因此在该数据库中的类名(列名)将是简单的 'name' ,这就是为什么我将 name 放在 value 字段中......
I am assuming that your table name is class as you want to show class name so in that database class name (column name) would be simple 'name' , that why I put name in value field....
这篇关于如何在 Laravel 中从外键中查看表字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
