Laravel Update Syntax - Updating Record with Array Laravel Update Syntax - Updating Record with Array laravel laravel

Laravel Update Syntax - Updating Record with Array


Instead of this line:

$updateOrder = Order::update($thisOrderID, $thisOrder);

You need to do:

$updateOrder = Order::find($thisOrderID)->update($thisOrder);

With find() (which equals where_id()) you select a specific row from the database and with update you pass the new data.


What do you think of this:

//Handle a new order POSTRoute::post('order', array('do' => function() {    $thisOrder = array(         'qty' => Input::get('quantity'),         'desc' => Input::get('description'),    );    $thisOrderID = Input::get('orderNo');    $order = Order::find( $thisOrderID );    //CHECK FOR NEW OR EXISTING ORDER    if( $order ) {        $order->title = 'New order title';        $order->desc = 'New description';        $order->save();    }}


erm , I will suggest to do it this way, if $thisOrder include the key, it will just update the record, else it will just create a new record.

$thisOrder = array(     'orderNo' => Input::get('orderNo'),     'qty' => Input::get('quantity'),     'desc' => Input::get('description'),);$updateOrder = Order::save($thisOrder);

if Input::get('orderNo') no value will be create else update