douting0585 2016-08-23 07:20
浏览 32

Laravel Postgres整数[]列从多个选择表单插入

So basically I got two tables, GameIDs table with client_game_id (int) column and Settings table with subscribed (integer[]) array type column. Got multiple select form that lists all game ids from game_ids and got to store them in the array type column. The tables got no relation.

    <div class="form-group">
      <label for="games">Games</label><br>
      <select name="games" id="games" class="selectpicker" multiple data-selected-text-format="count > 3" title="Choose games...">
      @foreach($clientgameids as $clientgameid)
        <option value="{{ $clientgameid->client_game_id }}">{{ $clientgameid->client_game_name }}</option>
      @endforeach
      </select>
    </div>

How do I prefix every item in the collection with '{}' since laravel does not support array[] columns and store it in the table ?

  • 写回答

1条回答 默认 最新

  • douxing6434 2016-08-23 08:30
    关注

    use name="games[]" instead of name="games" in view

    <select name="games[]" id="games" class="selectpicker" multiple data-selected-text-format="count > 3" title="Choose games...">
    

    write like this way in view

    {!!Form::open(array('route'=>'insert','id'=>'frmsave','method'=>'post'))!!}
    <div class="form-group">
          <label for="games">Games</label><br>
          <select name="games[]" id="games" class="selectpicker" multiple data-selected-text-format="count > 3" title="Choose games...">
          @foreach($clientgameids as $clientgameid)
            <option value="{{ $clientgameid->client_game_id }}">{{ $clientgameid->client_game_name }}</option>
          @endforeach
          </select>
        </div>
    
    {!!Form::hidden('_token',csrf_token())!!}
    {!!Form::close()!!}
    

    in route.php

    Route::post('/insert',array('as'=>'insert','uses'=>'yourcontrollername@insert'));
    

    then in controller write

    public function insert(){
            $gm=Input::get('games');
            var_dump($gm);
    foreach ($pricepr as $key => $v) {
     $data=array(
         'table_coln_name' => $gm,
       );
    yourmodel::insert($data);
    
     }//foreach end
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码