当前位置:网站首页>Laravel cross database query
Laravel cross database query
2022-06-09 08:10:00 【xcbzsy】
One 、SQL sentence
Across the database :env(‘LARGE_DATABASE’)
$sql = " SELECT b.operator,count(DISTINCT a.id) qty FROM proofing_notice a JOIN proofing_notice_operator b ON a.id = b.notice_id LEFT JOIN deve_color c on a.color_id = c.id LEFT JOIN ". env('LARGE_DATABASE') ."large_color d on a.color_id = d.id WHERE a.id= b.notice_id and a.status = ". $status_for_sql ." AND b.flag = ". $flag_for_sql ." AND a.area_id in (" .$place_from_str.") AND a.deleted_at IS NULL AND c.deleted_at IS NULL AND d.deleted_at is NULL ";
if ($status_for_sql == 9) {
$sql .= " AND !(a.paper_type_id =0 AND a.delivery_date IS NULL) GROUP BY b.operator";
}else{
$sql .= " GROUP BY b.operator";
}
$nodo = DB::select($sql);
Two 、laravel Model
Across the database LARGE_DATABASE: from(DB::raw(env(“LARGE_DATABASE”)
$grid = new Grid(new ProofingNotice());
$grid->model()->with(['sizegroup','notice_cad.user_name','notice_operater.user_name','area',
'notice_node_new'=>function($q){
$q->with(['deve_sales_name','deve_aid_name','deve_buyer_name']);
},
// Development
'exploit'=>function($q) {
$q->with(['client','brand', 'quarters','client_branch','devedep']);
},
'colors'=>function($q){
$q->with(['place','devecert', 'sizegroup']);
},
'colors_with_trashed'=>function($q){
$q->with(['place','devecert', 'sizegroup']);
},
// Big goods
'largesizegroup', 'large_styles'=>function($q){
$q->with(['quarters','client','cate','deve_style']);
},
'large_colors'=>function($q){
$q->with(['order'=>function($qa){
$qa->with(['client_dept','brand','size_group']);
}]);
},
'large_colors_with_trashed'=>function($q){
$q->with(['order_with_trashed'=>function($qa){
$qa->with(['client_dept','brand','size_group','deve_style']);
}]);
}])
->whereIn('area_id',$area_id);
// Inquire about
if($search) {
// There are query conditions
$grid->model()->where('status','>',$status1);
$grid->model()->where('status','<',18);
// Check development
$grid->model()->whereHas('exploit',function ($q) use($search){
$q->where('exploit_no', 'like', "%{
$search}%")->orWhere('style_name', 'like', "%{
$search}%");
});
$grid->model()->orWhereHas('colors_with_trashed',function ($q) use ($search){
$q->where('color_no', 'like', "%{
$search}%");
});
// Check the big goods
$grid->model()->orWhereHas('large_styles',function ($q) use ($search){
$q->from(DB::raw(env("LARGE_DATABASE")."large_style"))->where(env("LARGE_DATABASE").'large_style.large_no', 'like', "%{
$search}%");
});
$grid->model()->orWhereHas('large_colors_with_trashed',function ($q) use ($search){
$q->from(DB::raw(env("LARGE_DATABASE")."large_color"))->where(env("LARGE_DATABASE").'large_color.color_no', 'like', "%{
$search}%");
});
$grid->model()->orWhereHas('large_colors_with_trashed',function ($q) use ($search){
$q->from(DB::raw(env("LARGE_DATABASE")."large_color"));
$q->whereHas('order_with_trashed',function($qa) use ($search){
$qa->from(DB::raw(env("LARGE_DATABASE")."large_order"))->where(env("LARGE_DATABASE").'large_order.large_name', 'like', "%{
$search}%");
$qa->from(DB::raw(env("LARGE_DATABASE")."large_order"))->orWhere(env("LARGE_DATABASE").'large_order.order_no', 'like', "%{
$search}%");
});
});
}
else{
// No query criteria
if ($tag == 1){
$grid->model()->whereIn('status',$status2);
if($type == 11){
$grid->model()->where(function ($q){
$q-> where('paper_type_id', 1);
$q->orWhere(function ($qa){
$qa->where('paper_type_id', 0);
$qa->whereNotNull('delivery_date');
});
});
}
}
else{
// Approved by the technology department
$grid->model()->whereIn('state',$status2);
}
}
边栏推荐
- Clickhouse distributed table & local table & Clickhouse realize time series data management and mining
- CV learning notes cnn-vgg
- 苹果胜诉 法官驳回iPhone安全欺诈集体诉讼
- Breakthrough in customer experience in the insurance industry through low code and no code
- Go questions / knowledge gathering - 2
- MySQL: connection query
- Market Research - current market situation and future development trend of functional paper additives in the world and China
- Report on Market Research and future forecast of Chinese pharmaceutical rubber stopper (2022 Edition)
- Market Research - current situation and future development trend of high frequency welded finned tube Market in the world and China
- SQL or NoSQL, you will understand after reading this article
猜你喜欢

Oracle: time type

Will ebpf be the future of service grid?

Compiling opencv4.5.5 with CUDA (4.2.0+cuda11.1+cudnn8.0.5 failed)

Leetcode: find the number of recent palindromes

C language review 7

At time_ What happens to TCP connections in wait status after SYN is received?

Blow up the idea artifact in use recently

苹果胜诉 法官驳回iPhone安全欺诈集体诉讼
Twitter的最新功能让商家预告即将推出的产品 提醒顾客去购物

C语言复习11
随机推荐
Research and investment strategy report on China's FRP membrane shell industry (2022 Edition)
ELK+Filebeat 部署安装
苹果胜诉 法官驳回iPhone安全欺诈集体诉讼
How about opening an account for shares of tongdaxin? Is it safe to open an account?
ELK集群设置账号密码认证
[introduction to the paper] 2204 Vqgan-clip (open source):open domain image generation and editing with natural language guidance
xml-json-yaml 互转
POI,Cos实现Excel文件上传下载
Go questions / knowledge gathering - 2
Global and China flywheel energy storage development research and future forecast report (2022 Edition)
TCP transmission control protocol
Résumé des connaissances de base redis (hyper détaillé)
Report on Market Research and future forecast of Chinese pharmaceutical rubber stopper (2022 Edition)
Market Research - current situation and future development trend of global and Chinese dental zirconia disc Market
Summary of MySQL knowledge points
The cumulative net worth of more than 1100 products fell below 0.8. Is the performance of private placement good this year?
YOLOv5添加注意力机制的具体步骤
Record some common C library functions and UNIX system calls
MySQL common interview knowledge points
At time_ What happens to TCP connections in wait status after SYN is received?