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 = 11This 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.
更多推荐
发布评论