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 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输