繁体   English   中英

如何用php和sql代码匹配两个表?

[英]how to match two tables with php and sql code?

我有两个表:一个用于学生,一个用于交易,我需要查询以将交易表中的 id 与 id_student 匹配,因为 id_student 是学生表的外键,该表以 id 列作为主键。 我从交易 controller 中的以下代码中一无所获。

$trades = new trades();
    $trades = students::orderBy('created_at','desc')->where('id_student', '=', auth()->id_student())
    ->with(['trades'])
    ->first();

使用auth()->user()->id_student而不是auth()->id_student()

$trades = Students::orderBy('created_at','desc')
    ->where('id_student', auth()->user()->id_student)
    ->with(['trades'])
    ->first();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM