<?php

namespace App\Http\Controllers;

use App\OrderPackage;
use Illuminate\Http\Request;

class OrderPackageController extends Controller
{
    public function update(Request $request)
    {
        $remarkItem = $request->input('remark');
        /**
         * @var $orderPackage OrderPackage
         */
        $orderPackage = OrderPackage::query()->find($request->input('orderPackageId'));
        if (is_null($orderPackage->remark)) {
            $orderPackage->remark = [$remarkItem];
        } else {
            $remark = $orderPackage->remark;
            $remark[] = $remarkItem;
            $remark = array_reverse($remark);
            $orderPackage->remark = $remark;
        }
        $orderPackage->save();
        return ['success' => true, 'data' => $orderPackage->refresh()->remark];
    }

}
