如何在 laravel 中提交表单之前在模态中添加附加值输入

How to add additional input with value in modal before form submit in laravel

我用laravel 7。我想在提交前添加额外的模态值。 当我尝试在没有其他模式的情况下更新数据时,更新工作正常。但是,当我添加具有价值的附加模态时,程序成功但我的更新无法正常工作。这是我的表格(blade 视图):

<div class="col-md-10">
                <form method="POST" action="{{ url('/quotation/updateQuotation', $id) }}"
                    enctype="multipart/form-data">
                    @csrf
                    <div class="card">
                        <div class="card-body bg-light-white ">
                            <div class="tab-content">
                                <table width="100%">
                                    <tr>
                                        <td>Quotation No<span class="required" style="color: red">*</span></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <span style="display: flex;">
                                                    <input type="text" name="qno" style="width: 20%;"
                                                        class="form-control form-control-sm"
                                                        value="{{ $qno }}" readonly />

                                                    <input type="text" name="quotation_no" style="width: 60%;"
                                                        class="form-control form-control-sm"
                                                        value="{{ $quotation->quotation_no }}" readonly />
                                                </span>
                                            </div>
                                        </td>

                                        <td>Quotation Date<span class="required" style="color:red"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <input type="date" name="quotation_date"
                                                    class="form-control form-control-sm"
                                                    value="{{ $quotation->quotation_date }}" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Ref. No</td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <input type="text" name="ref_no" style="width: 80%"
                                                    class="form-control form-control-sm"
                                                    value="{{ $quotation->ref_no }}" />
                                            </div>
                                        </td>

                                        <td>Request Date</td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <input type="date" name="request_date"
                                                    class="form-control form-control-sm"
                                                    value="{{ $quotation->request_date }}" />
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Request By</td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <input type="text" name="request_by"
                                                    class="form-control form-control-sm"
                                                    value="{{ $quotation->request_by }}" style="width: 80%" />
                                            </div>
                                        </td>

                                        <td>Currency<span class="required" style="color:red"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select class="form-control selectpicker" data-live-search="true"
                                                    style="width: 80%;" aria-label="1 -10" id="currency"
                                                    name="currency">
                                                    {{-- munculkan option data dari table --}}
                                                    <option value="{{ $quotation->currency }}" selected>
                                                        {{ $quotation->currency }}</option>
                                                    {{-- list option dari table currency --}}
                                                    @foreach ($curency as $val2)
                                                        <option value="{{ $val2->code }}"
                                                            data-token="{{ $val2->name }}">{{ $val2->code }}
                                                        </option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Insurance Period<span class="required" style="color:red"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <span style="display: flex;">
                                                    <input type="date" name="start_period" style="width: 40%;"
                                                        class="form-control form-control-sm"
                                                        value="{{ $quotation->start_period }}" />

                                                    <input type="date" name="end_period" style="width: 40%;"
                                                        class="form-control form-control-sm"
                                                        value="{{ $quotation->end_period }}" />
                                                </span>
                                            </div>
                                        </td>

                                        <td>Quotation Type</td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select name="quotation_type" class="form-control" id="quotation_type">
                                                    @if ($quotation->quotation_type == 1)
                                                        <option value="1">Tipe 1</option>
                                                    @endif
                                                    @if ($quotation->quotation_type == 2)
                                                        <option value="2">Tipe 2</option>
                                                    @endif
                                                    <option value="1">Tipe 1</option>
                                                    <option value="2">Tipe 2</option>
                                                </select>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Ceding<span class="required"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select class="form-control selectpicker" data-live-search="true"
                                                    name="ceding_id" style="width: 80%;" aria-label="1 -10" required>
                                                    @if ($quotation->ceding_id == null)
                                                        <option value="" data-tokens=""></option>
                                                    @endif
                                                    @foreach ($cedding as $val2)
                                                        @if ($quotation->ceding_id == $val2->code)
                                                            <option value="{{ $val2->code }}"
                                                                data-tokens="{{ $val2->name }}">
                                                                {{ $val2->code . '-' . $val2->name }}</option>
                                                        @endif
                                                    @endforeach
                                                    @foreach ($cedding as $val2)

                                                        <option value="{{ $val2->code }}"
                                                            data-tokens="{{ $val2->name }}">
                                                            {{ $val2->code . '-' . $val2->name }}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </td>
                                        <td>Payment Mode</td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select class="form-control selectpicker" data-live-search="true"
                                                    aria-label="1 -10" name="payment_mode" id="payment_mode">
                                                    @if ($quotation->payment_mode == 1)
                                                        <option value="1">Annually</option>
                                                    @endif
                                                    @if ($quotation->payment_mode == 2)
                                                        <option value="2">Semi Annually</option>
                                                    @endif
                                                    @if ($quotation->payment_mode == 4)
                                                        <option value="4">Quaterly</option>
                                                    @endif
                                                    @if ($quotation->payment_mode == 12)
                                                        <option value="12">Monthly</option>
                                                    @endif
                                                    <option value="1">Annually</option>
                                                    <option value="2">Semi Annually</option>
                                                    <option value="4">Quaterly</option>
                                                    <option value="12">Monthly</option>
                                                </select>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Company<span class="required"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select class="form-control selectpicker" data-live-search="true"
                                                    name="company_profile" style="width: 80%;" aria-label="1 -10"
                                                    required>
                                                    @if ($quotation->company_profile == null)
                                                        <option value="" data-tokens=""></option>
                                                    @endif
                                                    @foreach ($company as $val2)
                                                        @if ($quotation->company_profile == $val2->company_profile)
                                                            <option value="{{ $val2->company_profile }}"
                                                                data-tokens="{{ $val2->company_profile }}" selected>
                                                                {{ $val2->company_profile }}</option>
                                                        @endif
                                                    @endforeach
                                                    @foreach ($company as $val2)
                                                        <option value="{{ $val2->company_profile }}"
                                                            data-tokens="{{ $val2->company_profile }}">
                                                            {{ $val2->company_profile }}</option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </td>
                                        <td>Installment<span class="required" style="color:red"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <input id="installment" type="text" name="qty_installment"
                                                    class="form-control" readonly
                                                    value="{{ $quotation->qty_installment }}">
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Product Brand<span class="required"></td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select class="form-control selectpicker" data-live-search="true"
                                                    name="product_brand" style="width: 80%;" aria-label="1 -10"
                                                    required>
                                                    @if ($quotation->product_brand == null)
                                                        <option value="" data-tokens=""></option>
                                                    @endif
                                                    @foreach ($productbrand as $val2)
                                                        @if ($quotation->product_brand == $val2->product_brand && $quotation->company_profile == $val2->company_profile && $quotation->ceding_id == $val2->ceding_id)
                                                            )
                                                            <option value="{{ $val2->product_brand }}"
                                                                data-tokens="{{ $val2->product_brand }}">
                                                                {{ $val2->product_brand . '-' . $val2->description }}
                                                            </option>
                                                        @endif
                                                    @endforeach
                                                    @foreach ($productbrand as $val2)
                                                        <option value="{{ $val2->product_brand }}"
                                                            data-tokens="{{ $val2->product_brand }}">
                                                            {{ $val2->product_brand . '-' . $val2->description }}
                                                        </option>
                                                    @endforeach
                                                </select>
                                            </div>
                                        </td>
                                        <td>Quotation Category</td>
                                        <td>
                                            <div class="form-group col-md-9">
                                                <select name="quotation_category" class="form-control"
                                                    id="quotation_category">
                                                    @if ($quotation->quotation_category == 'konvensional')
                                                        <option value="konvensional">Konvensional</option>
                                                    @endif
                                                    @if ($quotation->quotation_category == 'syariah')
                                                        <option value="syariah">Syariah</option>
                                                    @endif
                                                    <option value="konvensional">Konvensional</option>
                                                    <option value="syariah">Syariah</option>
                                                </select>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                

                            </div>
                        </div>
                        <div class="align-items-right">
                            {{-- <button class="btn btn-success" style="float: right; margin: 10px;">
                                {{ __('Simulasi Premi ') }}
                            </button> --}}
                            {{-- <input type="submit" class="btn btn-success" value="Update"
                                style="float: right; margin: 10px;"> --}}

                            <button type="button" class="btn btn-success" data-id="2014-123456" data-toggle="modal"
                                data-target="#modalRevisi">Update</button>

                        </div>
                    </div>

                    {{-- start here modal revisi --}}
                    <div id="modalRevisi" class="modal fade" role="dialog">
                        <div>
                            <div class="modal-dialog">

                                <!-- Modal content-->
                                <div class="modal-content">
                                    <div class="modal-header" style="height:50px;">
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    </div>
                                    <div class="modal-body">

                                        <label>Revisi:</label>
                                        <select name="tipe_revisi" id="tipe_revisi" class="form-control">
                                            <option value="internal">Internal</option>
                                            <option value="eksternal">Eksternal</option>
                                        </select>
                                    </div>
                                    <div class="modal-footer text-center" style="display:inline;">
                                        <!-- <input type="submit" class="btn btn-primary" value="Cash" name="login" style="background-color:rgb(0,30,66); "> -->
                                        <button type="button" class="btn btn-danger"
                                            data-dismiss="modal">Cancel</button>
                                        <input type="submit" class="btn btn-primary" value="Submit" name="submit"
                                            style="background-color:rgb(0,30,66); ">
                                    </div>
                                </div>

                            </div>
                        </div>
                        {{-- </form> --}}
                    </div>
                    {{-- end here modal revisi --}}
                </form>
            </div>

这是第一个更新控制器:

public function updateQuotation(Request $request,QuotationLog $log, $id)
{
    // dd($request);
    $user = Auth::user();
    $validator = $request->validate([
        'qno' => 'required',
    ]);
    // dd($request->product_plan);
    $quotation = Quotation::find($id);
    if ($validator) {
        try{
        $quotation = Quotation::find($id);
        $quotation->qno = $request->qno;
        $quotation->quotation_no = $request->quotation_no;
        $quotation->quotation_date = $request->quotation_date;
        $quotation->ref_no = $request->ref_no;
        $quotation->request_date = $request->request_date;
        $quotation->request_by = $request->request_by;
        $quotation->currency = $request->currency;
        $quotation->start_period = $request->start_period;
        $quotation->end_period = $request->end_period;
        $quotation->quotation_type = $request->quotation_type;
        $quotation->quotation_category = $request->quotation_category;
        $quotation->payment_mode = $request->payment_mode;
        $quotation->qty_installment = $request->qty_installment;
        $quotation->ceding_id = $request->ceding_id;
        $quotation->company_profile = $request->company_profile;
        $quotation->product_brand = $request->product_brand;
        $quotation->expired_claim_receipt = $request->expired_claim_receipt;
        $quotation->overwrite_membership_premi_f = $request->overwrite_membership_premi_f;
        $quotation->prorate_claim_f = $request->prorate_claim_f;
        $quotation->uw_year = $request->uw_year;
        
        $quotation->user = $user->name;
        $quotation->tipe_revisi = $user->tipe_revisi;
        $quotation->save();

        //update table log
        $log->qno = $request->qno;
        $log->quotation_no = $request->quotation_no;
        $log->quotation_date = $request->quotation_date;
        $log->ref_no = $request->ref_no;
        $log->request_date = $request->request_date;
        $log->request_by = $request->request_by;
        $log->currency = $request->currency;
        $log->start_period = $request->start_period;
        $log->end_period = $request->end_period;
        $log->quotation_type = $request->quotation_type;
        $log->quotation_category = $request->quotation_category;
        $log->payment_mode = $request->payment_mode;
        $log->ceding_id = $request->ceding_id;
        $log->company_profile = $request->company_profile;
        $log->product_brand = $request->product_brand;
        $log->expired_claim_receipt = $request->expired_claim_receipt;
        $log->overwrite_membership_premi_f = $request->overwrite_membership_premi_f;
        $log->prorate_claim_f = $request->prorate_claim_f;
        $log->uw_year = $request->uw_year;
        $log->remarks = $request->remarks;
        $log->kind_of_contract = $request->kind_of_contract;
        $log->user_id = $user->id;
        $log->user_name = $user->name;
        $log->ip_address = $this->get_client_ip();
        $log->action = 'EDIT';
        $log->tipe_revisi = $user->tipe_revisi;
        $log->save();
        $notification = array(
            'message' => 'Quotation updated successfully!',
            'alert-type' => 'success'
        );
        return back()->with($notification);
        }catch (\Illuminate\Database\QueryException $ex) {
            dd($ex);
            $message = DB::table('health_sys_error')
            ->select('error_message')
            ->where('error_id','=',$ex->errorInfo[1])
            ->first();
            $notification = array(
                'message' => $message->error_message == null ? 'Error, Contact Admin!' : $message->error_message,
                'alert-type' => 'error'
            );
            return back()->with($notification)->withInput();
        }
    } else {
        return back()->with($validator)->withInput();
    }
}

我已经完成添加模型和迁移。我的程序 return 成功,但是 tipe_revisi 字段没有插入。为什么?

我认为您应该更改此代码,因为这是表单中的字段名称。

$user->tipe_revisi

$request->tipe_revisi

使用

$quotation->tipe_revisi = $request->tipe_revisi;

改为

$quotation->tipe_revisi = $user->tipe_revisi;

因为你从表单中获取数据