在<label>Enter value </label><input type = "search" id="txt_auto" onsearch="fillValue(event)" onkeyup="fillValue(event)"/>
<br/>
<label>Will be auto filled</label>
<input type = "text" id="txt_auto_fill" />
中尝试实施此{s}命令我没有收到任何错误 laravel 5
:
phpmyadmin
将此查询以laravel为:
SELECT shoppings.*, sum(shoppings.ordering_count)
FROM `shoppings` join products on products.id = shoppings.product_id
where `shoppings`.`user_ordering_ip` = '127.0.0.1'
我收到此错误:
$userShoppings = \DB::table('shoppings')
->join('products', 'shoppings.product_id', '=', 'products.id')
->select('*', \DB::raw('sum(shoppings.ordering_count)'))
->where('shoppings.user_ordering_ip', "'".request()->ip()."'")
->get();
答案 0 :(得分:1)
尝试使用以下查询,此处'
没有request()->ip
引号,我怀疑您不是在这里调用ip()
方法,也不要在这里使用sum
方法
$userShoppings = \DB::table('shoppings as s')
->join('products as p', 's.product_id', '=', 'p.id')
->select('p.*','s.*')
->where('s.user_ordering_ip', request()->ip())
->get();
$sum_of_ordering_count = $userShoppings->sum('ordering_count');
答案 1 :(得分:0)
我认为您的查询是正确的。
您可以尝试使用以下查询代码。
$userShoppings = \DB::table('shoppings')
->join('products', 'shoppings.product_id', '=', 'products.id')
->select('shoppings.*', \DB::raw('sum(shoppings.ordering_count)'))
->where('shoppings.user_ordering_ip', '=', '127.0.0.1')
->get();
此外,似乎request()->ip