drus39136 2016-09-17 09:23
浏览 23
已采纳

更改付款状态按钮会出现错误“创建默认对象...”

I'm trying to make 2 buttons with Mars as Paid and Mark as Unpaid values 1/0.

When I click on button I've got error:

Creating default object from empty value

What is wrong with the code? I know it can be write more 'intelligent'. Here is the controller

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', '');
}

And here is view buttons

{{ 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() }}
  • 写回答

1条回答 默认 最新

  • doulan6150 2016-09-17 09:26
    关注

    Seem like the problem is in your controller where you take paid value from the form. Try to replace:

    $paid->paid
    

    whit

    $paid['paid']
    

    On this line

    $paid->paid = Input::get('paid');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析