有第一个表goods,字段ex_buyed, 第二个表orders, 有app\Models\Goods.php和app\Models\Order.php,有app\Http\Home\OrderController.php,有routes\common\web.php。请用 laravel 实现 select a.ex_buyed from goods a,orders b where b.goods_id = a.id and b.id='8' and b.status=4 ,并在resources\views\luna\static_pages\orderinfo.blade.php 显示{{$order['ex_buyed']}} 在app\Http\Home\OrderController.php中,使用如下代码: public function orderinfo() { $orders = DB::select('select a.ex_buyed from goods a,orders b where b.goods_id = a.id and b.id=? and b.status=?', [8, 4]); return view('luna.static_pages.orderinfo', compact('orders')); }
时间: 2023-04-12 21:00:42 浏览: 118
freemarket_sample_51a
好的,我明白了。以下是您要求的答案:
在 Laravel 中实现 select a.ex_buyed from goods a,orders b where b.goods_id = a.id and b.id='8' and b.status=4 的代码如下:
$orders = DB::table('goods as a')
->join('orders as b', 'b.goods_id', '=', 'a.id')
->select('a.ex_buyed')
->where('b.id', '=', '8')
->where('b.status', '=', 4)
->get();
在 resources\views\luna\static_pages\orderinfo.blade.php 中,显示 {{$order['ex_buyed']}} 的代码如下:
{{$orders[0]->ex_buyed}}
在 app\Http\Home\OrderController.php 中,实现上述代码的方法如下:
public function orderinfo()
{
$orders = DB::table('goods as a')
->join('orders as b', 'b.goods_id', '=', 'a.id')
->select('a.ex_buyed')
->where('b.id', '=', '8')
->where('b.status', '=', 4)
->get();
return view('luna.static_pages.orderinfo', compact('orders'));
}
阅读全文