我尝试制作Mars as Paid
和Mark as Unpaid
值为1/0的2个按钮。
当我点击按钮时,我遇到了错误:
Creating default object from empty value
代码有什么问题?我知道它可以写得更多,更聪明' 这是控制器
public function ordersPaidSubmit($orderId) {
$order = Order::where('order_id', $orderId)->first();
if (!$order) {
App::abort(404);
}
$paid->paid = Input::get('paid');
$order->save();
return Redirect::to('/orders')->with('message', '');
}
这是视图按钮
{{ Form::open() }}
@if($order->paid = 0)
<button type="submit" class="btn btn-primary" name="paid" id="paid" value="1">Mark Order as Paid</button>
@else
<button type="submit" class="btn btn-primary" name="paid" id="paid" value="0">Mark Order as Unpaid</button>
@endif
{{ Form::close() }}
答案 0 :(得分:1)
似乎问题出现在您的控制器中,您从表单中获取paid
值。尝试替换:
$paid->paid
丝毫
$paid['paid']
在这一行
$paid->paid = Input::get('paid');