lundi 2 mai 2016

Problems updating additional column on just one Laravel pivot record

When trying to update just one record of a pivot_table, this method updates all records with the same user_id and order_id. Only records that match the order_id, user_id, stage_id and finished_at = null should be updated.

public function pause($id)
{
    $order = Order::find($id);
    $now = Carbon::now();
    $stage = Status::find($order->status_id)->stage_id;

    $users = $order
        ->user()
        ->where('status_id', $order->status_id)
        ->where('finished_at', null)
        ->get();

    foreach($users as $user)
    {
        $user->pivot->finished_at = $now;
        $user->pivot->save();
    }

    flash()->success('Progress paused for order #' . $order->order_number .'.');
    return redirect('/department/' . $stage);

}

Before running pause method: image before running pause method

After running pause method enter image description here



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SGqqDi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire