SQL中的雄辩(SQL in Eloquent)

系统教程 行业动态 更新时间:2024-06-14 17:02:18
SQL中的雄辩(SQL in Eloquent)

如何看待这个与雄辩的查询?

Select * from tableOne left join tableTwo on (tableOne.ID = tableTwo.ID) where tableOne.Number = 11

这是我想改变的雄辩的陈述

$var = table::where('Number', '=', $varInput)->get();

how would look this query with eloquent?

Select * from tableOne left join tableTwo on (tableOne.ID = tableTwo.ID) where tableOne.Number = 11

This is my eloquent statement that I want to change

$var = table::where('Number', '=', $varInput)->get();

最满意答案

Amr Aly是正确的,你可以解决这个问题:

DB::table('tableOne')->join('tableTwo', 'tableOne.id', '=', 'tableTwo.id')->where('tableOne.Number', '=', $varInput)->get();

然而; 我强烈建议你看看利用雄辩和定义关系。 如果您的模型设置正确,您可以执行以下操作:

$tableOne = TableOne::with('tableTwo')->find($id); $tableTwo = $tableOne->tableTwo;

您可以阅读更多关于在Laravel文档中定义关系的信息 。

Amr Aly is correct that you can solve this with:

DB::table('tableOne')->join('tableTwo', 'tableOne.id', '=', 'tableTwo.id')->where('tableOne.Number', '=', $varInput)->get();

However; I would strongly recommend you look into taking advantage of Eloquent and defining relationships. If your models were setup properly you could do something like the following:

$tableOne = TableOne::with('tableTwo')->find($id); $tableTwo = $tableOne->tableTwo;

You can read more about defining relationships in the Laravel Documentation.

更多推荐

本文发布于:2023-04-21 18:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/de1905774127c73b5923ff816ba6877f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:雄辩   SQL   Eloquent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!