Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel中编写子查询?_Php_Mysql_Laravel_Subquery_Laravel Query Builder - Fatal编程技术网

Php 如何在laravel中编写子查询?

Php 如何在laravel中编写子查询?,php,mysql,laravel,subquery,laravel-query-builder,Php,Mysql,Laravel,Subquery,Laravel Query Builder,如何以雄辩的格式转换此查询 这是我的模型 $get_duplicate=DB::select('select * from student_info a join ( select first_name, last_name, dob from student_info group by first_name, last_name, dob having count(*) > 1 ) b on a.first_name = b.first_name and a.last_name = b

如何以雄辩的格式转换此查询

这是我的模型

$get_duplicate=DB::select('select * from student_info a join ( select first_name, last_name, dob  from student_info group by first_name, last_name, dob having count(*) > 1 ) b on a.first_name = b.first_name and a.last_name = b.last_name and a.dob = b.dob join participant_info on participant_info.id = a.participant_id order by a.first_name ASC');

我已经编辑了前面的代码。请试试这个

<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class StudentInfo extends Model
{
    //
    public $timestamps = true;
    protected $table = 'student_info';
    protected $guarded = array();
    public function student_participant_det(){
        return $this->hasOne('App\Model\ParticipantInfo', 'id','participant_id');

    }
}

我已经编辑了前面的代码。请试试这个

<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class StudentInfo extends Model
{
    //
    public $timestamps = true;
    protected $table = 'student_info';
    protected $guarded = array();
    public function student_participant_det(){
        return $this->hasOne('App\Model\ParticipantInfo', 'id','participant_id');

    }
}

让我们看看您的模型及其关联关系。“StudentInfo”是一个模型,请在您的问题中添加任何相关代码,评论中没有。现在你能帮我吗?请你也显示
particantinfo
好吗。让我们看看你的模型及其关联关系。“StudentInfo”是一个模型,请在你的问题中输入任何相关代码,不在评论中。现在你能帮我吗?请你也显示
ParticpantInfo
好吗。谢谢@mith我已经找到了解决方案。。。。谢谢你的帮助:)谢谢@mith我已经找到了解决办法。。。。谢谢你的帮助:)