laravel框架踩过的坑
1、数据库的原生使用
文档:https://learnku.com/docs/laravel/5.8/queries/3926,DB:row
需要在查询中使用原生表达式,selectRaw
方法可以代替 select(DB::raw(...))
。该方法的第二个参数是可选项,值是一个绑定参数的数组:
$orders = DB::table('orders') ->selectRaw('price * ? as price_with_tax', [1.0825]) ->get();
eg:
$data = https://www.it610.com/article/$recoveryOrder->leftJoin('user_wechats', 'recovery_orders.user_id', '=', 'user_wechats.user_id')
->leftJoin('recovery_order_expresses', 'recovery_orders.id', '=', 'recovery_order_expresses.order_id')
->leftJoin('recovery_order_senders', 'recovery_orders.id', '=', 'recovery_order_senders.order_id')
->leftJoin('recovery_order_receivers', 'recovery_orders.id', '=', 'recovery_order_receivers.order_id')
->select( 'recovery_orders.order_number',
'recovery_orders.created_at',
'recovery_orders.cashback_money',
'recovery_order_senders.sender_name',
'recovery_order_senders.sender_phone',
'recovery_order_senders.sender_province_name',
'recovery_order_senders.sender_city_name',
'recovery_order_senders.sender_county_name',
'recovery_order_senders.sender_detail_address',
'recovery_orders.meet_at',
'recovery_orders.remark_from_user',
'recovery_orders.cargo_name',
'recovery_orders.estimated_weight',
DB::raw("CASE recovery_orders.is_cashback WHEN 'Yes' THEN '已返现' WHEN 'No' THEN '未返现' ELSE '未知' END as is_cashback"),
DB::raw("CASE recovery_orders.order_status WHEN 'CREATED' THEN '创建成功' WHEN 'ASSIGNED' THEN '等待上门' WHEN 'RECEIVED' THEN '已取货' WHEN 'SIGNED' THEN '已签收' WHEN 'CANCELLED' THEN '已取消' ELSE '未知状态' END as order_status"),
'recovery_order_expresses.express_company_name',
'recovery_order_expresses.express_number',
'recovery_order_expresses.weight_from_express',
'recovery_orders.user_id',
'recovery_order_expresses.remark_from_express',
'recovery_orders.cancelled_reason',
'recovery_orders.remark_from_admin',
'user_wechats.open_id'
)
->selectRaw('(SELECT
GROUP_CONCAT(recovery_order_waybills.tracking_number)
FROM
recovery_order_waybills
WHERE
recovery_order_expresses.id = recovery_order_waybills.order_express_id
) AS tracking_number'
)
->distinct()
->orderBy('recovery_orders.created_at','desc')
->paginate($request->limit);
【laravel框架踩过的坑】转载于:https://www.cnblogs.com/hjcan/p/10812233.html
推荐阅读
- android第三方框架(五)ButterKnife
- 标签、语法规范、内联框架、超链接、CSS的编写位置、CSS语法、开发工具、块和内联、常用选择器、后代元素选择器、伪类、伪元素。
- Spring|Spring 框架之 AOP 原理剖析已经出炉!!!预定的童鞋可以识别下发二维码去看了
- 构建App(一)(框架与结构)
- laravel框架泛解
- spring事务管理_01:事务管理框架+声明式事务
- Java集合框架|Java集合框架 数据结构
- 集合框架(集合嵌套存储和遍历元素的案例代码实现)
- 论框架思维
- Android轻松实现跨进程/跨app通讯框架及其原理