Monday, April 10, 2017

Laravel , geeting comma separated values as ID for another model

so i have this input from invoice_table, "order_numbers", with values something like this : 91,92,93

in controller :

$invoice->order_numbers = Input::get('order_numbers');

What i need is to find that order numbers ( 91,92,93 ) in orders_table and updated it's value

This is what i try in controller :

$invoice->order_numbers = Input::get('order_numbers');
$orderIds = explode(',', $invoice->order_numbers);
    $cnt = count($orderIds);

    for ($i = 0; $i < $cnt; $i++) {
        $order = Order::findOrFail($orderIds);
        $order->is_billed = '1';

        $order->save();

    }

but i got this error : BadMethodCallException in Macroable.php line 74: Method save does not exist.

Can somebody help me what to do ? Thanks



via Rifki Carlos Rinaldi

Advertisement