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

时间:2016-09-17 09:23:21

标签: php laravel-4 laravel-blade

我尝试制作Mars as PaidMark 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() }}

1 个答案:

答案 0 :(得分:1)

似乎问题出现在您的控制器中,您从表单中获取paid值。尝试替换:

$paid->paid

丝毫

$paid['paid']

在这一行

$paid->paid = Input::get('paid');