亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel:如何將重復的輸入名稱發送到控制器中的 update()

Laravel:如何將重復的輸入名稱發送到控制器中的 update()

PHP
慕仙森 2023-09-22 16:32:14
我想更新 laravel 中 cms 的設置形式。問題:我的列只有option_name和value如何解決存儲數據的輸入名稱問題?使用數組作為輸入名稱?數據庫圖像移民:Schema::create('settings', function (Blueprint $table) {    $table->id();    $table->string('option_name');    $table->longText('value');    $table->timestamps();});設置.blade.php<form action="{{ route('setting.update', [ 'settings' => $value]) }}" method="POST">    @csrf    @method('PUT')    <input name="value" value="{{ $settings->find(1)->value }}" type="text">    @error('value') <p class="customized-errors">{{ $message }}</p> @enderror        <input name="value" value="{{ $settings->find(2)->value }}" type="text">    @error('value') <p class="customized-errors">{{ $message }}</p> @enderror        <input name="value" value="{{ $settings->find(6)->value }}" type="text">    @error('value') <p class="customized-errors">{{ $message }}</p> @enderror        <input  name="value" {{ (($settings->find(3)->value) == 1)? 'checked' : '' }} type="checkbox" class="filled-in chk-col-primary" id="checkbox2">    <label class="col-10 col-form-label text-label lable-customized text-cu"> ??????? ?? ?????? ??? ????? ???? </label>        <input name="value" {{ (($settings->find(4)->value) == 1)? 'checked' : '' }} checked type="checkbox" class="filled-in chk-col-primary" id="checkbox2">    <label class="col-10 col-form-label text-label lable-customized text-cu"> ??????? ?? ?????? ?????? ??? ??? ?? ??? ???? </label>    </form>
查看完整描述

1 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

將所有輸入設置為動態輸入,就像name=value[]
現在在控制器中一樣dd($request->value),您將獲得此輸入名稱作為數組,例如:

[value] => Array(
    [1] => value 1
    [2] => value 2
    [3] => value 3
    [4] => value 4
    [5] => value 5
    [6] => value 6
    [7] => value 7)

我認為您不需要動態輸入,在這種情況下您只需將name屬性更改為name="site_name"name="site_description"name="can_register"name="can_comment"name="auto_accept_comment"name="can_post_page"name="can_index"。


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 94 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號