Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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
在关系的最后记录中搜索-Laravel(雄辩)_Laravel_Search_Eloquent_Wherehas - Fatal编程技术网

在关系的最后记录中搜索-Laravel(雄辩)

在关系的最后记录中搜索-Laravel(雄辩),laravel,search,eloquent,wherehas,Laravel,Search,Eloquent,Wherehas,我需要在Laravel 7中搜索一段关系的最后记录。这是我的代码,希望你能理解我的问题:) ServiceRequest有许多SignatureFlow,但我只需要搜索最后插入的流。我认为当我使用->latest()时,我的搜索只能在最后一行搜索666,但不会发生。 谢谢删除中的返回,您可以创建新的关系HasOne,并根据它进行过滤 public function ServiceRequestSignatureLastFlow() { return $this->hasOne(Ser

我需要在Laravel 7中搜索一段关系的最后记录。这是我的代码,希望你能理解我的问题:)

ServiceRequest有许多SignatureFlow,但我只需要搜索最后插入的流。我认为当我使用->latest()时,我的搜索只能在最后一行搜索666,但不会发生。
谢谢

删除
中的
返回
您可以创建新的关系
HasOne
,并根据它进行过滤

public function ServiceRequestSignatureLastFlow()
{
   return $this->hasOne(ServiceRequestSignatureFlows::class)->orderByDesc('id');
}

$collection = ServiceRequest::whereHas('ServiceRequestSignatureLastFlow', function ($query) use ($ou_id) {
        $query->where('user_id', $ou_id);
    })->orderBy('name', 'ASC')->get();
$collection = ServiceRequest::whereHas('ServiceRequestSignatureLastFlow', function ($query) use ($ou_id) {
        $query->where('user_id', $ou_id);
    })->orderBy('name', 'ASC')->get();