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

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

如何從陣列輸入中刪除不需要的值?

如何從陣列輸入中刪除不需要的值?

PHP
慕神8447489 2022-07-09 09:57:06
我只是想問一下我們如何避免這種來自陣列輸入的輸出。每次我更新它時,這些符號 ["\"[ 都會不斷增加。我將向您展示問題和下面的代碼。謝謝你未來的答案。Route::resource('setups','SetupController');public function index()    {       $data = DB::table('setups')->first();        if (!empty($data)) {                    $socials = explode(',',$data -> social);        }else{            $socials = [];        }        return view ('adminpanel.setup.index',['data' => $data,'socials' => $socials]);    }index.blade.php<form action="{{ route('setups.edit',$data->id) }}"><div class="row">  <div class="col-md-12" id="socialGroup">    @foreach($socials as $social)    <div class="form-group socialField">    <label class="bmd-label-floating">Social Links</label>      <input type="text" name="social[]" value="{{$social}}" class="form-control" disabled>      <a href="#" class="addField"><i class="fa fa-plus"></i></a>    </div>    @endforeach    <div class="alert alert-danger" id="socialError">    <p><strong>Sorry! </strong>You've reached the max number for social links form.</p>    </div>  </div></div><form>.public function edit($id)    {        $data = DB::table('setups')->first();        $setup = DB::table('setups')->where('id', $id)->first();        if (!empty($data)) {                    $socials = explode(',',$data -> social);        }else{            $socials = [];        }        if($setup){        return view ('adminpanel.setup.edit',['data' => $data,'socials' => $socials]);        }else{            return redirect('setups');        }    }.
查看完整描述

2 回答

?
慕雪6442864

TA貢獻1812條經驗 獲得超5個贊

laravel 默認轉義數據。每當您從數據庫中檢索數據以放入刀片視圖時,它都沒有給出任何錯誤。數據庫數據轉義是一種很好的做法。


當您顯示數據時,有一些不需要的數據。在嘗試保存數據之前,您可以trim($yourString)從字符串的開頭和結尾刪除不需要的空格。


并且您不能讓空白或空字符串在您的刀片中查看。那么,您可能會使用blank($var)它來檢查它是否為空白?


<form method="POST" action="{{ route('setups.update', $data->id) }}">

 <div class="row">

  <div class="col-md-12" id="socialGroup">

    @foreach($socials as $social)

      @if(!blank($social))

       <div class="form-group socialField">

         <label class="bmd-label-floating">Social Links</label>

         <input type="text" name="social[]" value="{{ $social }}" class="form-control">

         <a href="#" class="addField"><i class="fa fa-plus"></i></a>

       </div>

      @endif

    @endforeach

    <div class="alert alert-danger" id="socialError">

     <p><strong>Sorry! </strong>You've reached the max number for social links form.</p>

    </div>

  </div>

</div>


查看完整回答
反對 回復 2022-07-09
?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

解決了!我剛剛在我的 SetupController@update 中添加了這段代碼


if (Input::has('social')) {

            $data['social'] = implode(',',$data['social']);

    }

http://img1.sycdn.imooc.com//62c8e0c100013bac05690061.jpg


查看完整回答
反對 回復 2022-07-09
  • 2 回答
  • 0 關注
  • 161 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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