Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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 拉威尔有什么口才_Php_Laravel_Eloquent - Fatal编程技术网

Php 拉威尔有什么口才

Php 拉威尔有什么口才,php,laravel,eloquent,Php,Laravel,Eloquent,laravel雄辩的框架有点麻烦 我需要复制如下查询: SELECT * FROM RepairJob WHERE NOT EXISTS (SELECT repair_job_id FROM DismissedRequest WHERE RepairJob.id = DismissedRequest.repair_job_id); 现在我有 $repairJobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')-&

laravel雄辩的框架有点麻烦

我需要复制如下查询:

SELECT *
FROM RepairJob
WHERE NOT EXISTS (SELECT repair_job_id
    FROM DismissedRequest
    WHERE RepairJob.id = DismissedRequest.repair_job_id);
现在我有

 $repairJobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')->where('active', '=', 'Y')->whereNotExists('id', [DismissedRequest::all('repair_job_id')])->get();
有人有主意吗?我需要获得所有在“已驳回请求”表中没有记录的维修工作

我在使用上述查询时遇到此错误

Argument 1 passed to Illuminate\Database\Query\Builder::whereNotExists() must be an instance of Closure, string given
试试这个:

$repairJobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
              ->where('active', '=', 'Y')
              ->whereNotExists(function($query)
                {
                    $query->select(DB::raw(1))
                          ->from('DismissedRequest')
                          ->whereRaw('RepairJob.id = DismissedRequest.id');
                })->get();
请尝试doesntHave()方法。假设“dismissedRequests”作为RepairJob模型中的关系名称

$jobs = RepairJob::with('repairJobPhoto', 'city', 'vehicle')
    ->where('active', 'Y')->doesntHave('dismissedRequests')->get();

whereNotExists
接受一个函数并更改
$query
。查看
何处存在的文档:这不是很有说服力吗?感谢您的回复,但是如果我将这一行代码更改为这一行,我会得到上面更新中提到的错误。有什么想法吗?所以,我想您使用barryvdh/laravel cors包来处理cors。确保将
cors
中间件应用到路由或组以添加cors支持。示例:
Route::group(['middleware'=>'cors'],函数(Router$Router){$Router->get('api'),'ApiController@index'); });。另一种方法是添加
cors
作为全局中间件,如果您想将其应用于所有路由。谢谢,此代码干净有效,问题是语法错误:):)与Phargelm的代码有相同的错误,请查看上面的更新,有什么想法吗?感谢您的回复。这是CORS-正确配置您的服务器(appache,nginx,?)并创建新问题-不要在这里混淆这两个问题。感谢此解决方案,我将其用作本地范围,效果非常好。我建议使用
whereColumn
而不是
whereRaw
这也适用于无说服力的查询生成器