gpt4 book ai didi

mysql - 将 mySQL 查询转换为具有多个条件的 Laravel 5

转载 作者:行者123 更新时间:2023-11-29 21:10:16 25 4
gpt4 key购买 nike

我有这种 mySQL 查询。我用它来搜索许可证_id、电子邮件(用户)、机器_id

SELECT license.license_id, license.instances, license.expiry_date,license.license_type, users.email 
FROM license
INNER JOIN purchase_items ON purchase_items.license_id = license.license_id
INNER JOIN customer_purchases ON customer_purchases.customer_purchase_id = purchase_items.customer_purchase_id
INNER JOIN users ON users.user_id = customer_purchases.customer_id
INNER JOIN machines ON machines.license_id = license.license_id
WHERE customer_purchases.status = 1
AND license.license_id LIKE '%9fe%'
OR users.email LIKE 'hora%'
OR machines.machine_id LIKE '%dfd3%'
GROUP BY license.license_id

这里我开始在 Laravel 5 中这样写

     $key = $request->search_key;         
if(($request->session()->get('user'))!=null){
$license_data = License::join('purchase_items','license.license_id','=','purchase_items.license_id')
->join('customer_purchases','customer_purchases.customer_purchase_id','=','purchase_items.customer_purchase_id')
->join('users','users.user_id','=','customer_purchases.customer_id')
->where('customer_purchases.status','=',1)
//some more codes
->groupBy('license.license_id')
->select('license.license_id',
'license.expiry_date',
'license.instances',
'users.email',
'license.license_type',
'license.is_valid')
->paginate(10);

我不明白如何使用多个条件。

($key表示搜索关键字与url一起出现)

最佳答案

使用

$license_data = License::join('purchase_items','license.license_id','=','purchase_items.license_id')->join('customer_purchases','customer_purchases.customer_purchase_id','=','purchase_items.customer_purchase_id')->join('users','users.user_id','=','customer_purchases.customer_id')->where('customer_purchases.status','=',1)->orwhere('license.license_id','LIKE',$key)->orwhere('users.email','LIKE',$key)->orwhere('machines.machine_id','LIKE',$key)->groupBy('license.license_id') ->select('license.license_id', 'license.expiry_date', 'license.instances','users.email',  'license.license_type',license.is_valid')->paginate(10); 

关于mysql - 将 mySQL 查询转换为具有多个条件的 Laravel 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36443414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com