Php 拉维计数单
我有一个简单的应用程序,它只在同一天计算我的订单和付款总额,并在表中提交。我有一个抽屉,每天开始,当完成当天我可以提交一天的总金额(订单,付款/付款),在第二天我开始从零现金再次开始。 我的问题是:是否有可能在同一天结束我的抽屉并重新开始,每天多次使用0现金? 现在,如果我重新开始,我会看到今天已经完成的所有订单 我的控制器:Php 拉维计数单,php,laravel,Php,Laravel,我有一个简单的应用程序,它只在同一天计算我的订单和付款总额,并在表中提交。我有一个抽屉,每天开始,当完成当天我可以提交一天的总金额(订单,付款/付款),在第二天我开始从零现金再次开始。 我的问题是:是否有可能在同一天结束我的抽屉并重新开始,每天多次使用0现金? 现在,如果我重新开始,我会看到今天已经完成的所有订单 我的控制器: public function show($id) { $locations = Location::find($id)->orders()
public function show($id)
{
$locations = Location::find($id)->orders()->whereDate('created_at', '=', Carbon::today()->toDateString()); //show orders
$wallets = Location::find($id)->locsales()->whereDate('created_at', '=', Carbon::today()->toDateString()); //show payments
$loc = Location::find($id); //to show location name
return view('location')
->with('locations', $locations)
->with('wallets', $wallets)
->with('loc', $loc);
}
我的部分看法是:
<div class="card-body">
<div class="form-group">
<div class="list-group-item">
<label for="location">Location: {{$loc->location_id}}</label>
<form method="post" action="/post_drawer">
@csrf
<input type="number" class="form-control" name="start_cash" id="start_cash" value="{{$wallets->sum('start_cash')}}" readonly>
<label for="info">Amount of orders(today):</label>
<input type="number" class="form-control" name="amount" id="amount" value="{{$locations->sum('total')}}" readonly>
可能是我做错了什么,但没用
更新2:我使我的控制器只显示值为1的记录,现在它工作正常
$locations = Location::find($id)->orders()
->where('added_to_drawer', 1)
$affected = DB::table('orders')->whereid('location', $id)->update(array('added_to_drawer' => 0));
$affected = DB::table('wallets')->where('location_id', $id)->update(array('added_to_drawer' => 0));
但我还有一个问题。当我关闭抽屉时,他会更新(重置)所有位置
抽屉到0。
例如,我只想更新这个名称为newyork但要动态更新的位置。不是这样:where('location','=','newyork')
我这样试过:
where('location','='$id)
,但它不起作用。当你想启动新的抽屉时,你可以尝试在orders表中使用另一个字段,比如added_to_drawer
使用布尔值,使所有都为true,在查询中你可以写入->whereNull('added_to_drawer')
用您所做的事情和错误来更新您的问题?
$locations = Location::find($id)->orders()
->where('added_to_drawer', 1)
$affected = DB::table('orders')->whereid('location', $id)->update(array('added_to_drawer' => 0));
$affected = DB::table('wallets')->where('location_id', $id)->update(array('added_to_drawer' => 0));